我目前在Ext JS 3.1.0中教授EditorGridPanel。我设法创建了一个显示城市列表的网格。但是,当我尝试将新记录添加到数据库时,我遇到了问题。当我点击“添加城市”按钮时,没有任何反应,Firebug显示错误:
Uncaught ReferenceError: newCity is not defined
Ext.grid.EditorGridPanel.tbar.handlereg02.html: 96
Ext.Button.Ext.extend.onClickext-all-debug.js: 27083
h
这是我的代码:
Ext.onReady(function(){
//===== Data Store ================================================== (2)
var store = new Ext.data.Store({
url: 'city_for_eg01.php',
reader: new Ext.data.JsonReader({
root:'rows',
id:'zip'
}, [
'zip',
'city'
]),
api: {
create : 'city_for_eg01.php?action=create',
read : 'city_for_eg01.php?action=read',
update: 'city_for_eg01.php?action=update',
destroy: 'city_for_eg01.php?action=destroy'
},
writer: new Ext.data.JsonWriter({
writeAllFields: true
}),
autoSave: false,
});
store.load();
//=================================================================== end (2)
var editor = new Ext.form.TextField();
var grid = new Ext.grid.EditorGridPanel({
renderTo: document.body,
frame:true,
title: 'City',
height:200,
width:520,
clickstoEdit: 1,
store: store,
columns: [
{header: "ZIP", dataIndex: 'zip', editor: editor},
{header: "CITY", dataIndex: 'city', editor: editor},
],
listeners: {
afteredit: function(e){e.record.commit();}
},
tbar: [{
text: 'Add City',
icon: 'images/table_add.png',
cls: 'x-btn-text-icon',
handler: function() {
Ext.Ajax.request({
url: 'city-update.php',
params: {
action: 'create',
zip: 'zip'
},
success: function(resp,opt) {
grid.getStore().insert(0,
new newCity{
zip: 'New Zip',
city: 'New City'
})
);
grid.startEditing(0,0);
},
failure: function(resp,opt) {
Ext.Msg.alert('Error','Unable to add city');
}
});
}
}]
});
});
答案 0 :(得分:1)
这是因为没有定义newCity
函数。
你应该能够使用它:
new store.recordType(/* values */)
recordType
包含该商店的新Record
的构造函数。