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”}
      ,那么您确实丢失了数据
    • 必须在
      reader
      config中设置包含数据项的属性的名称。在extjs4中,这可以通过
      root
      完成,在extjs5,6中,这可以通过
      rootProperty
      完成
    • 如果按代码加载存储数据,请将
      autoLoad
      设置为
      false
    ExtJS4.2

    reader: {
        type: 'json',
        root: 'data'
    }   
    
    extjs5和extjs6

    reader: {
        type: 'json',
        rootProperty: 'data'
    }   
    
    注:

    我用EXTJS 4.2复制了您的测试用例,以下是导致这种行为的原因:

    • JSON响应不包含数据

    • 未设置
      root
      rootProperty
      )配置

    • JSON响应包含数据,但包含此数据的属性的名称与
      reader
      config中的名称不同

    工作示例:

    服务器响应:

    {
        "success": true,
        "data": [
            {"text": "Some words"},
            {"text": "Some words"},
            {"text":"Some words"}
        ]
    }
    
    HTML:


    您的
    DeptModel
    在哪里?