Extjs客户端数据,Grid展示,弹出窗体修改,并将修改数据再次显示在Grid【未完全验证】

【方式一】

1.弹出窗体的时候,传入参数,record。

2.record.get(’name‘)这样给form里的控件赋值

3.窗体验证

form.checkChange();  //这句话随时监听变化并验证
if (form.isValid())

4.获得窗体上的值

var form = btn.up('tms_test02Window').down('form');
var values = form.getForm().getValues();

 

5.修改之后,点击’保存‘按钮,时间里写:record.get('name')=values['name']  //values['name']里的name是控件的name属性的值。

6.record.commit();

【方式二】

修改方式一的5,6步骤。思路:store里面删除一条记录,然后插入一条记录

5.创建一个新的record

5.1创建一个Model

 1         Ext.define('TestModel', {
 2             extend: 'Ext.data.Model',
 3             fields: [
 4                     { name: 'idno' },
 5                     { name: 'gender' },
 6                     { name: 'name' },
 7                     { name: 'birthdate' },
 8                     { name: 'college' },
 9                     { name: 'major' },
10                     { name: 'education' },
11                     { name: 'enterdate' },
12                     { name: 'marrige' },
13                     { name: 'spousename' },
14                     { name: 'childnum' },
15                     { name: 'cellphone' },
16                     { name: 'email' },
17                     { name: 'emergencyperson' },
18                     { name: 'cellphone2' },
19                     { name: 'department' },
20                     { name: 'post' },
21                     { name: 'isactive' }
22           ]
23         });

5.2给record赋值

 1 var newRecord = Ext.create('TestModel', {
 2             idno: values['idno'],
 3             name: values['name'],
 4             gender: parseInt(values['gender']) ? '' : '',
 5             birthdate: values['date'],
 6             college: values['college'],
 7             major: values['major'],
 8             education: values['education'],
 9             enterdate: values['enterdate'],
10             marrige: values['marrige'],
11             spousename: values['spousename'],
12             childnum: values['childnum'],
13             cellphone: values['cellphone'],
14             email: values['email'],
15             emergencyperson: values['emergencyperson'],
16             cellphone2: values['cellphone2'],
17             department: values['department'],
18             post: values['post'],
19             isactive: values['isactive'] ? true : false
20 
21         });
 1   form.checkChange();
 2         if (form.isValid()) {
 3             if (btn.up('tms_test02Window').edit) {
 4                 store.removeAt(me.rowIndex);
 5                 store.insert(me.rowIndex, newRecord);
 6             }
 7             else {
 8                 store.add(newRecord);
 9             }
10             //store.reload();
11             btn.up('tms_test02Window').hide();
12         }
13         else {
14             alert('Please fill the form correctly.');
15         }

store.removeAt(me.rowIndex);   //移除原有record
store.insert(me.rowIndex, newRecord); //添加新的record,rowIndex为给窗体传的值,是插入的位置

posted @ 2014-04-04 09:41  大漠孤烟~  阅读(443)  评论(0编辑  收藏  举报