我想从服务器获取一些数据并评估它
如果我在json中评估1个元素,它工作正常,但如果我更多,我得到一个错误
这是操作(对ajax使用jquery):
,getColsFromServer : function(){
return [new Ext.grid.RowNumberer(),
Ext.util.JSON.decode('{"id":"id","dataIndex":"id","header":"ID","width":"20","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}},{"dataIndex":"email","header":"Title","width":"120","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}}')//,{"id":"pixels","dataIndex":"pixels","header":"pixels","width":"120","sortable":"true","editor":{"xtype":"textarea","allowBlank":"false"}})
];
}
如果你看看,我有2列id +电子邮件。
使用2列返回错误:
this.config [col]未定义
[中断此错误]返回this.config [col] .width;
使用一栏 - 工作正常。
这是上下文: 我想建立自己的网格对象,所以这是用法:
var grid = new Ext.grid.GridPanel({
loadMask: true,
store: store,
margins: '0 5 5 5',
autoExpandColumn: 'id',
plugins: [editor],
tbar: minisites.getTopBar(editor,store,grid),
bbar: minisites.getPagingBar(store , 1),
columns: minisites.getCols()// THIS FUNCTION WILL RETURN THE OBJ FROM THE SERVER USING SYNCED AJAX REQUEST
});
有什么想法吗?
答案 0 :(得分:1)
如果要评估多个对象,则应将它们放在数组中。 例如:
Ext.util.JSON.decode('[{"id":"id","dataIndex":"id","header":"ID","width":"20","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}},{"dataIndex":"email","header":"Title","width":"120","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}}]')
编辑:
如果你想返回一个哈希来通过一个名字访问每个项目(“id”和“email”,如果我做对了),你应该这样做:
Ext.util.JSON.decode('{ "id": {"id":"id","dataIndex":"id","header":"ID","width":"20","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}}, "email": {"dataIndex":"email","header":"Title","width":"120","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}}}')
编辑#2:
在此上下文中,“getColsFromServer”应返回如下列的数组:
getColsFromServer : function(){
return Ext.util.JSON.decode('[{"id":"id","dataIndex":"id","header":"ID","width":"20","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}},{"dataIndex":"email","header":"Title","width":"120","sortable":"true","editor":{"xtype":"textfield","allowBlank":"false"}}]');
}
答案 1 :(得分:0)
我怀疑您的列定义不正确。如果您为此更改代码,控制台中会显示什么?
var col = minisites.getCols();// THIS FUNCTION WILL RETURN THE OBJ FROM THE SERVER USING SYNCED AJAX REQUEST
console.dir(col);
var grid = new Ext.grid.GridPanel({
loadMask: true,
store: store,
margins: '0 5 5 5',
autoExpandColumn: 'id',
plugins: [editor],
tbar: minisites.getTopBar(editor,store,grid),
bbar: minisites.getPagingBar(store , 1),
columns: col
});