【发布时间】:2016-02-10 09:16:57
【问题描述】:
我正在下面更改我的代码,并希望以下拉列表的形式显示我的树结构
https://jsfiddle.net/sjmcpherso/kc9fehyz/
var vDOM = document.createDocumentFragment(); //Create a Document Fragment to store your Virtual DOM
function formCategoryTrees(object,par) { //Use the parent node as a parameter to create hierarchy
var ul = document.createElement('ul');
_.each(object,function(objectValues ){
var li = document.createElement('li');
var leafCategoryId = objectValues["id"];
var leafCategoryName = objectValues["name"];
li.appendChild(document.createTextNode(leafCategoryName + " " + leafCategoryId));
if(objectValues["children"]) {
formCategoryTrees(objectValues["children"],li);
}
ul.appendChild(li);
})
par.appendChild(ul); //Append to the parent node after each iteration
}
formCategoryTrees(object.records,vDOM);
document.body.appendChild(vDOM); //Append your Virtual DOM to your page
【问题讨论】:
-
那么,有什么问题?
-
我想在下拉列表而不是 jstree 中显示它
-
@vini 你是怎么实现这个的?
-
@ShervinShahrdar 我用过 jstree。
标签: javascript html tree dropdown