1
我試圖創建樹的JSON爲建立一個jqtree以下數據jqtree構建樹的JSON從數據
var data = [
{
"director": "Name1",
"name": "sub-sub-child1",
"teamname": "sub-child1",
"teamManager": "child1"
},
{
"director": "Name1",
"name": "sub-sub-child2",
"teamname": "sub-child1",
"teamManager": "child1"
},
{
"director": "Name1",
"name": "sub-sub-child2",
"teamname": "sub-child2",
"teamManager": "child2"
},
{
"director": "Name2",
"name": "sub-sub-child1",
"teamname": "sub-child1",
"teamManager": "child1"
},
{
"director": "Name2",
"name": "sub-sub-child2",
"teamname": "sub-child2",
"teamManager": "child2"
},
{
"director": "Name3",
"name": "sub-sub-child1",
"teamname": "sub-child1",
"teamManager": "child1"
},
{
"director": "Name3",
"name": "sub-sub-child2",
"teamname": "sub-child2",
"teamManager": "child2"
}
];
console.log(data);
var aNode = [];
var aTempNode = [];
$.each(data, function(index, value) {
//console.log(value);
var key = {};
if($.inArray(value.director, aTempNode) == -1) {
aTempNode.push(value.director);
key['label'] = value.director;
key['children'] = [{label: value.teamManager, children: [{label: value.teamname, children: [{label: value.name}]}]}];
aNode.push(key);
} else {
//console.log(aNode)
if(key['teamname'] == aNode.children) {
}
}
});
console.log(aNode);
EDIT2
樹應該是在這種形式下
Name1
|
|___child1
| |
| |___sub-child1
| | |
| | |___sub-sub-child1
| | |___sub-sub-child2
| |
| |___sub-child2
| |
| |___sub-sub-child1
| |___sub-sub-child2
|
|____child2
編輯1
我已經半途而廢了。我很困惑如何從這裏開始。 fiddle
非常感謝你,它就像一個魅力,但它產生空兒節點雖然沒有孩子。 http://jsfiddle.net/ts9v17xt/28/ – user525146