extjs4存储回调函数don';没有记录
存储回调,如下所示:extjs4存储回调函数don';没有记录,extjs,callback,extjs4,store,Extjs,Callback,Extjs4,Store,存储回调,如下所示: var store = new Ext.create("Ext.data.TreeStore", { model: "DeptModel", proxy: { type: 'ajax', url: 'jsonWebCommMenuOp_getMenus?PID=0', reader: 'json' }, autoload: true }); store.load({ callback:
var store = new Ext.create("Ext.data.TreeStore", {
model: "DeptModel",
proxy: {
type: 'ajax',
url: 'jsonWebCommMenuOp_getMenus?PID=0',
reader: 'json'
},
autoload: true
});
store.load({
callback: function(records, options, success) {
var jsonStr = Ext.JSON.encode(records[0].raw);
var jsonObj = Ext.JSON.decode(jsonStr);
alert(jsonStr);
}
});
{
"success": true,
"msg": "123"
}
服务器响应如下:
var store = new Ext.create("Ext.data.TreeStore", {
model: "DeptModel",
proxy: {
type: 'ajax',
url: 'jsonWebCommMenuOp_getMenus?PID=0',
reader: 'json'
},
autoload: true
});
store.load({
callback: function(records, options, success) {
var jsonStr = Ext.JSON.encode(records[0].raw);
var jsonObj = Ext.JSON.decode(jsonStr);
alert(jsonStr);
}
});
{
"success": true,
"msg": "123"
}
我测试回调参数成功
,它等于真
,但记录
为空[]
原因是什么?请帮助我。下面有几点您需要用代码重新检查:-
自动加载
而不是自动加载
TreeStore
您应该提到root:{}
data.json
请求
希望这对你有帮助/指导。 在你的情况下,你必须考虑以下事项:
- 您的服务器响应到底是什么。如果它是
,那么您确实丢失了数据{“success”:true,“msg”:“123”}
- 必须在
config中设置包含数据项的属性的名称。在extjs4中,这可以通过reader
完成,在extjs5,6中,这可以通过root
完成rootProperty
- 如果按代码加载存储数据,请将
设置为autoLoad
false
reader: {
type: 'json',
root: 'data'
}
extjs5和extjs6
reader: {
type: 'json',
rootProperty: 'data'
}
注:
我用EXTJS 4.2复制了您的测试用例,以下是导致这种行为的原因:
- JSON响应不包含数据
- 未设置
(root
)配置rootProperty
- JSON响应包含数据,但包含此数据的属性的名称与
config中的名称不同reader
{
"success": true,
"data": [
{"text": "Some words"},
{"text": "Some words"},
{"text":"Some words"}
]
}
HTML:
您的
DeptModel
在哪里?