jstree 返回的JSON字符串怎么拼写 10C

{
"text": "一级机构",
"children":
[
{
"text": "二级机构",
"icon": "fa fa-folder icon-state-danger",
"state": {
"selected": true
}
},
{
"text": "二级机构",
"icon": "fa fa-folder icon-state-danger",
"children": [
{ "text": "三级机构", "icon": "fa fa-file icon-state-info" }
]
},
{
"text": "二级机构",
"icon": "fa fa-folder icon-state-danger"
},
{
"text": "二级机构",
"icon": "fa fa-folder icon-state-danger"
},
{
"text": "二级机构",
"icon": "fa fa-folder icon-state-danger",
"children": [
{ "text": "三级机构", "icon": "fa fa-file icon-state-info" },
{ "text": "三级机构", "icon": "fa fa-file icon-state-info" },
{ "text": "三级机构", "icon": "fa fa-file icon-state-info" },
{ "text": "三级机构", "icon": "fa fa-file icon-state-info" },
{ "text": "三级机构", "icon": "fa fa-file icon-state-info" }
]
}
]
}

2个回答

“拼写”不知道是什么意思,你是要给jstree设置节点,还是要读取?

caozhy
贵阳老马马善福专业维修游泳池堵漏防水工程 回复u012536675: 不需要拼接,直接传对象就可以。比如 data.text = "一级机构";
大约一年之前 回复
u012536675
whueuwe 就是在Ajax中怎么拼写这个JSON字符串,我会弄了,谢谢
大约一年之前 回复

类似下面这样,你没有id的话可以去掉

    joinNode = function(nodeArray,$treeObject) {
        var i = 0, nodeArrayLength = nodeArray.length;
        var $tree = $("#jstree1");
        $tree.html();
        if($treeObject == null){
            $treeObject = $tree;
        }
         var ul = $("<ul></ul>");
          $treeObject.append(ul);
        for(i = 0; i < nodeArrayLength; i++) {
            var node = nodeArray[i], liHtml = '',
                       $ddItem, fatherId = node.fatherId, $ddList, template, $ddListInModal;
            if(node.children != null){
                var li = $("<li id="+ node.id +"></li>");
                $(li).append(node.name).appendTo(ul);
                joinNode(node.children,li);
            }else{//标签为<file name="***"/>,file一定是叶子节点
                var li = $("<li id="+ node.id +"></li>");
                $(li).append(node.name).appendTo(ul);
            }
        }
    };
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!