页面调用如下方法
jsonTree();
function jsonTree(){
console.log("jsonTree is begin")
$.getJSON(ctx+"/node/treeNodesJson.js",function(json){
console.log("json data")
console.log(json)
})
console.log("jsonTree is end")
}
XHR 中显示json数据的文件也已经加载,但是回调函数就是不执行
最后发现是json的数据格式不正确--必须严格遵守json格式要求
var zNodes =[//不能写等号前的东西
{id:5, pId:0, name:"组合功能 演示", open:false},
{id:501, pId:5, name:"冻结根节点", file:"super/oneroot"},
{id:502, pId:5, name:"单击展开/折叠节点", file:"super/oneclick"},
{id:503, pId:5, name:"保持展开单一路径", file:"super/singlepath"},
{id:504, pId:5, name:"添加 自定义控件", file:"super/diydom"},
{id:505, pId:5, name:"checkbox / radio 共存", file:"super/checkbox_radio"},
{id:506, pId:5, name:"左侧菜单", file:"super/left_menu",
"children":[
{"id":513,"name":"资源1","num":0,"open":false,"pId":1},
{"id":514,"name":"资源2","num":0,"open":false,"pId":1},//这里的逗号不能有
]
},
{id:513, pId:5, name:"OutLook 样式的左侧菜单", file:"super/left_menuForOutLook"},
{id:507, pId:5, name:"下拉菜单", file:"super/select_menu"},//不能有逗号
];//不能有分号
1.json必须是对象或者数组
2.不能有多余的东西,严格的json格式
3.id、pid、name等必须加双引号