(對不起提前如果帖子是長的,我只是添加所有參與該問題的代碼,那麼我認爲這可能是更容易得到答案)ExtJS的4 updateRecord錯誤
你好,當我嘗試更新extjs 4中的商店時遇到問題。
要備份一點,我正在開發一個通用網格,您可以在其中發送所需的列以及窗口中的字段向網格添加新行,那麼這是普通格:
Ext.define('masterDataGridControls', {
extend : 'Ext.grid.Panel',
id : 'panelWin',
windowItems : null,
addWin : null,
initComponent : function() {
var me = this;
Ext.applyIf(me, {
dockedItems : [{
xtype : 'toolbar',
dock : 'top',
items : [{
xtype : 'button',
id : 'btn_delete',
iconCls : 'deleteIcon',
tooltip : 'Delete row or group',
handler : function() {
var selection = me.getView()
.getSelectionModel()
.getSelection()[0];
if (selection) {
store.remove(selection);
}
}
}, {
xtype : 'button',
id : 'btn_add',
iconCls : 'addIcon',
tooltip : 'Add row or group',
handler : me.addToList
}]
}]
});
me.callParent(arguments);
},
getAddWindow : function() {
if (!this.addWin) {
this.addWin = new windowPop({
formItems : this.windowItems,
idParent : this.config.id,
record : this.store.model.prototype
});
}
return this.addWin;
},
addToList : function() {
var addWindow = this.findParentByType().findParentByType()
.getAddWindow();;
addWindow.show();
}
});
和我有類windowPop那是誰收到的領域,它們顯示並保存數據的一個:
Ext.define("windowPop", {
extend : "Ext.window.Window",
formPanel : null,
formItems : null,
record : null,
idParent : null,
initComponent : function() {
var me = this;
me.formPanel = new Ext.form.Panel({
items : this.formItems,
layout: 'anchor'
});
Ext.applyIf(me, {
resizable : false,
closable : false,
width : 300,
minWidth : 300,
minHeight : 200,
y : 150,
layout : 'fit',
plain : true,
modal : true,
items : [me.formPanel],
buttons : [{
text : "i_Save",
handler : function() {
console.info(me.record);
me.formPanel.getForm().updateRecord(me.record);
Ext.getCmp(me.idParent).fireEvent("winSave",me.record);
me.formPanel.getForm().reset();
me.hide();
}
}, {
text : 'i_Cancel',
handler : function() {
me.formPanel.getForm().reset();
me.hide();
}
}]
});
me.callParent(arguments);
}
});
我有我的特定電網,在那裏我定義一個數據。模型和現在,我使用一個固定的店面,但後來將是一個我從服務器獲取替換:
Ext.define('userKeys', {
extend : 'Ext.data.Model',
fields : [{
name : 'text',
type : 'string'
}, {
name : 'description',
type : 'string'
}, {
name : 'group',
type : 'string'
}]
});
var store = Ext.create('Ext.data.Store', {
model: 'userKeys',
data : [{
text : "que mamera",
description : "asdfasdf",
group : 'homework'
}, {
text : "book report",
description : 'hola',
group : 'homework'
}, {
text : "alegebra",
description : "haha",
group : 'homework'
}, {
text : "buy lottery tickets",
description : "kajsdf",
group : 'homework'
}]
});
Ext.define('ConfigInterfacesUserKeys', {
extend : 'masterDataGridControls',
initComponent : function() {
var me = this;
me.columns = [{
id : 'cl_input',
header : 'i_Text',
dataIndex : 'text',
width : 220
}, {
header : 'i_Description',
dataIndex : 'description',
width : 130
}, {
header : 'i_group',
dataIndex : 'group',
width : 130
}];
me.windowItems = [{
xtype : 'textfield',
id : 'txt_sendTime',
fieldLabel : 'text',
margin : '5 0 0 5',
style : 'font-weight:bold',
labelWidth : 120,
name : 'text'
}, {
xtype : 'textfield',
id : 'txt_waitTime',
fieldLabel : 'description',
margin : '5 0 0 5',
style : 'font-weight:bold',
labelWidth : 120,
name : 'description'
}, {
xtype : 'textfield',
id : 'txt_group',
fieldLabel : 'group',
margin : '5 0 0 5',
style : 'font-weight:bold',
labelWidth : 120,
name : 'group'
}];
me.store = store;
me.callParent(arguments);
}
})
的問題
當我嘗試爲您在windowPop類林看到這樣做是爲了救場:
me.formPanel.getForm().updateRecord(me.record);
,但我得到了一個錯誤:
this[this.persistenceProperty] is undefined
我就找到了錯誤,我發現所有啓動時的功能updateRecord嘗試將對象設爲店:
updateRecord: function(record) {
var fields = record.fields,
values = this.getFieldValues(),
name,
obj = {};
fields.each(function(f) {
name = f.name;
if (name in values) {
obj[name] = values[name];
}
});
record.beginEdit();
**record.set(obj);**
record.endEdit();
return this;
}
我不知道這是否是有點問題,當我從一般電網模型發送到窗口,我把它這種方式:
record : this.store.model.prototype
然後我不知道如果它是因爲我發送它的模型不好的話。
我一直在尋找互聯網,但我找不到合適的答案,那麼如果你能以正確的方式指導我,這將非常有幫助。
感謝
它的工作:),那麼這個問題是因爲我發送已經填寫對象,我應該有發的模式,但空...非常感謝:)... –