我的Store是这么定义的:Ext.define("NP.store.Menus", {  
extend : "Ext.data.TreeStore",  
model : "NP.model.Menu",  
root : {  
expanded : true,  
text : "系统菜单",  
},  
proxy : {  
type : "rest",  
url : "menu",  
reader : {  
type : "json",  
root : "data",//这里如果设置成data.content就不对  
successProperty : "success"  
}  
}  
});  
服务器返回的JSON数据格式为:Js代码  
{  
    "data": {  
        "content": [  
            {  
                "id": 1,  
                "name": "系统管理",  
                "url": null,  
                "title": "系统管理",  
                "icon": null,  
                "parent": null,  
                "children": [],  
                "roles": [],  
                "userGroups": []  
            }  
        ]  
    },  
    "success": true  
}  
 因为我的模型数据集合是在数据的data.content里,而如果Store.proxy.reader.root设置成data.content 就会报错:Uncaught TypeError: Cannot read property 'content' of undefined这是什么原因啊 ? 请指点啊Ext JSJavaScript

解决方案 »

  1.   

    我发现当root设为data.content时,Ext根本没往后台发送请求
      

  2.   

    root指的就是根节点嘛。只能是data。不过你可以把content去掉。
    {  
        "data": {  
                    "id": 1,  
                    "name": "系统管理",  
                    "url": null,  
                    "title": "系统管理",  
                    "icon": null,  
                    "parent": null,  
                    "children": [],  
                    "roles": [],  
                    "userGroups": []  
        },  
        "success": true  
    }
      

  3.   


    因为Data里面不仅包含了content还包含一些其他的信息,最好是不要改动后台代码
      

  4.   

    treeStore 最好单独load,不要把和tree无关的信息也放到json里
    另外,root应该是children。当然,你也可以拿到json后,自己按从属关系往treestore里填加数据。
    var node = root.createNode( {
    id:data.content.id,
    ...
    } );
    root.appendChild(node);