我正在尝试显示一个包含部分及其包含的页面的 jstree。我已经为每个设置了一个类型,但我无法更改页面类型的图标,它只是一直显示默认文件夹图标。
这是我的 JavaScript:
$('#demo1').jstree({
"themes" : {
"theme" : "default",
"dots" : false,
"icons" : true
},
"types" : {
"section" : {
"max_children" : -1,
"max_depth" : -1,
"valid_children": "all",
"type_attr" : "section"
},
"page" : {
"max_children" : 0,
"max_depth" : -1,
"valid_children": "none",
"icon" : {
"image" : "http://static.jstree.com/v.1.0rc/_docs/_drive.png"
},
"type_attr" : "page"
}
},
"core" : {"html_titles" : true, "load_open" : true },
"plugins" : [ "themes", "json_data", "ui", "cookies", "crrm", "sort", "types" ],
"json_data" : {
"ajax" : {
"type": 'GET',
"url" : function (node) {
var url = ""
if (node == -1)
{
url = 'localhost/sections';
}
else
{
url = 'localhost/sections/'+node.attr("id");
}
return url;
},
"type" : "get",
"success" : function(items) {
data = []
for (i in items) {
var item = items[i]
var type;
if (JSON.stringify(items[i].root)) {
type = "section";
node = {
"data" : item.title,
"attr" : { "id" : item.id, "rel" : type },
"state" : "closed"
}
} else {
type = "page";
node = {
"data" : item.title,
"attr" : { "rel" : type },
"state" : "open"
}
}
this.set_type(type, node);
data.push(node);
}
return data;
}
}
}
});
这是由 AJAX 调用生成的 HTML。
<div id="demo1" class="demo jstree jstree-0 jstree-focused jstree-default" style="height:100px;">
<ul class="jstree-no-dots">
<li id="1" rel="section" class="jstree-open">
<ins class="jstree-icon"> </ins><a href="#" class="jstree-clicked"><ins class="jstree-icon"> </ins>One</a>
<ul>
<li id="3" rel="section" class="jstree-closed"><ins class="jstree-icon"> </ins><a href="#" class=""><ins class="jstree-icon"> </ins>One Subsection</a></li>
<li rel="page" class="jstree-open jstree-last"><ins class="jstree-icon"> </ins><a href="#" class=""><ins class="jstree-icon"> </ins>Page in section one</a></li>
</ul>
</li>
<li id="2" rel="section" class="jstree-closed jstree-last"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Two</a></li>
</ul>
</div>
谁能看到出了什么问题?
任何建议表示赞赏。
谢谢