我有一个选择的网格将记录绑定到表单。
gridSelectionChange: function (model, records) {
if (records[0]) {
this.getFormdata().getForm().loadRecord(records[0]);
}
},
一切正常,但如果我更改任何字段值,网格不会更新记录,也不会更新数据存储区。
我读过我必须打电话:
form.updateRecord();
但是如何在我的领域(文本字段,组合等)的每一个焦点丢失时调用它?
有没有办法进行双向绑定?
答案 0 :(得分:1)
你可以在Ext JS 4 SDK examples / app / simple / simple.html下看到一个工作示例 它将网格绑定到窗口内的表单。
这是解决问题的代码:
editUser: function(grid, record) { // this function fires when dblClick on itemRow
var edit = Ext.create('AM.view.user.Edit').show(); //creates a window a shows it
edit.down('form').loadRecord(record); //reference the form and load the record
},
updateUser: function(button) { //this function fires on save button of the form
var win = button.up('window'), //get a reference to the window
form = win.down('form'), // get a reference to the form
record = form.getRecord(), // get the form record
values = form.getValues(); // get the values of the form
record.set(values); //set the values to the record (same object shared with the grid)
win.close(); //close window
this.getUsersStore().sync(); // this line is only necesary if you want to synchronize with the server
}
底线:
var record = form.getRecord(),
values = form.getValues();
record.set(values);