【发布时间】:2015-10-01 18:21:39
【问题描述】:
我目前有一个 javascript 函数,它接受一维数组并将它们添加到树对象中。
var tree = {}
function addToTree(tree, arr) {
for (var i = 0, length = arr.length; i < length - 1; i++) {
tree = tree[arr[i]] = tree[arr[i]] || {};
}
tree[arr[i]] = null;
}
addToTree(tree, ["a", "b", "c", "f"])
addToTree(tree, ["a", "b", "d", "h", "l"])
我希望有人可以帮我格式化它,以便它将对象返回到与 JSTree 兼容的对象中:https://www.jstree.com/docs/json/
【问题讨论】:
标签: javascript arrays json jstree