JsTree树不出来 报Uncaught TypeError: Cannot read property 'children' of undefined
来源:互联网 发布:网络显卡联机 编辑:程序博客网 时间:2024/06/06 00:27
1、 问题
JsTree树不出来,从chrome console 看到
Uncaught TypeError: Cannot read property 'children' of undefined
2、code 和后台json数据
问题出自 黄色部分
---------------------------------------Code---------------------------------------------
var url = "${pageContext.request.contextPath}/tree/queryRoomTree.html";
$("#jstree_demo")
.jstree({
"core" : {
"animation" : 0,
"check_callback" : true,
'force_text' : true,
"themes" : { "stripes" : true },
"check_callback" : true,
'data' : function (obj, callback) {
var jsonstr="[]";
var jsonarray = eval('('+jsonstr+')');
$.ajax({
type: "POST",
url:url,
dataType:"json",
async: false,
success:function(result) {
var arrays= result;
for(var i=0 ; i<arrays.length; i++){
var arr = {
"id":arrays[i].id,
"parent":arrays[i].pid=="root"?"#":arrays[i].pid,
"text":arrays[i].name
}
jsonarray.push(arr);
}
}
});
callback.call(this, jsonarray);
}
},
"types" : {
"#" : { "max_children" : 1, "max_depth" : 4, "valid_children" : ["root"] },
"root" : { "icon" : "dist/images/tree_icon.png", "valid_children" : ["default"] },
"default" : { "valid_children" : ["default","file"] },
"file" : { "icon" : "glyphicon glyphicon-file", "valid_children" : [] }
},
"plugins" : ["checkbox", "contextmenu", "dnd", "search", "state", "types", "wholerow" ]
});
----------------------------------------------------------------------------------Data Json from backend--------------------------------------------------------------------------------------------------------
[
{"id":"-1","name":"鍏ㄩ儴绌鸿皟","pid":"","icon":null,"iconSkin":"root","open":false,"isParent":true,"checked":false},
{"id":"A1","name":"A妤 ","pid":"-1","icon":null,"iconSkin":"A","open":false,"isParent":true,"checked":false},
{"id":"A2","name":"B妤 ","pid":"-1","icon":null,"iconSkin":"A","open":false,"isParent":true,"checked":false},
{"id":"A3","name":"C妤 ","pid":"-1","icon":null,"iconSkin":"A","open":false,"isParent":true,"checked":false},
{"id":"A4","name":"D妤 ","pid":"-1","icon":null,"iconSkin":"A","open":false,"isParent":true,"checked":false},
3. 解决办法
因为后台返回的数据 根节点的"pid":""(空),而黄色代码部分却是
"parent":arrays[i].pid=="root"?"#":arrays[i].pid,
Code改为
"parent":arrays[i].pid==""?"#":arrays[i].pid,
//区别是绿色部分,也就是真正的根节点pid是““,赋值为#
- JsTree树不出来 报Uncaught TypeError: Cannot read property 'children' of undefined
- Extjs4---Uncaught TypeError: Cannot read property ‘items’ of undefined
- 【StackFlow】Uncaught TypeError: Cannot read property 'pageCount' of undefined
- Ckeditor: Uncaught TypeError: Cannot read property 'keyCode' of undefined 解决方法
- Uncaught TypeError: Cannot read property 'msie' of undefined问题解决方案
- Uncaught TypeError: Cannot read property 'options' of undefined 错误
- Uncaught TypeError: Cannot read property 'length' of undefined
- 错误:Uncaught TypeError: Cannot read property 'WebSocket' of undefined
- Uncaught TypeError: Cannot read property 'value' of undefined
- Uncaught TypeError: Cannot read property 'plugin' of undefined
- react Uncaught TypeError: Cannot read property 'title' of undefined
- Uncaught TypeError: Cannot read property 'width' of undefined
- Uncaught TypeError: Cannot read property 'substring' of undefined
- Uncaught TypeError: Cannot read property 'PRINT_INIT' of undefined user:100
- Uncaught TypeError: Cannot read property 'substring' of undefined
- extjs4:Uncaught TypeError: Cannot read property 'processed' of undefined
- Datatables 之Uncaught TypeError: Cannot read property 'mData' of undefined
- background.js Uncaught TypeError: Cannot read property 'xxx' of undefined
- java 中的大数据类型(BigInteger和BigDecimal)
- Linux上安装wildfly-10.1.0.Final并部署iServer9D war包
- Spring Boot 学习——Controller的使用
- 《鸟哥的Linux私房菜 基础学习篇(第三版)》习题与解析(四)
- HDU ACM2014
- JsTree树不出来 报Uncaught TypeError: Cannot read property 'children' of undefined
- javascript:;与javascript:void(0)使用介绍
- Codeforces 844 D Interactive LowerBound(随机化)
- 使用Object的直接实例构造轻量级的字典
- 垃圾回收器——CMS收集器
- 闭包
- hdu 4747Mex【线段树】
- Andoid NDK编程 2 - JNI签名规则
- 学习Linux-4.12内核网路协议栈(2.3)——接口层数据包的接收(下半部)