2011-11-09 44 views
2

我使用的Django Django的+ - MPTT完成一個雙贏的探險家樹一樣的界面與jstree:我通過Django的JSON數據Jstree,但它並沒有正常工作

{% load mptt_tags %} 
var nodedata = { 
    "data": { 
    {% recursetree nodes %} 
    "data": "{{ node.nodename }}", 
    "id": "{{ node.id }}", 
    "state":"open", 
    "children": [{ {{ children }} }], 
    {% endrecursetree %} 
    } 
}; 

它工作正常當每個節點只有一個孩子時。但是,當用戶創建一個以上的子節點,它擴展在jstree,如:

var nodedata = { 
    "data": { 

    "data": "following1", 
    "id": "1", 
    "state":"open", 
    "children": [{ 
    "data": "level3", 
    "id": "4", 
    "state":"open", 
    "children": [{ 
    "data": "level 4", 
    "id": "5", 
    "state":"open", 
    "children": [{ 
    "data": "New node", 
    "id": "6", 
    "state":"open", 
    "children": [{ 
    "data": "New node 2", 
    "id": "7", 
    "state":"open", 
    "children": [{ }], 
    }], 

    "data": "kkk", 
    "id": "8", 
    "state":"open", 
    "children": [{ }], 
    }], 
    }], 
    }], 

    } 
}; 

的「三K黨」節點演出,但「新節點」和「新節點2」不露面。

我在尋求一些建議,或者它是一種更好的方式來表示這棵樹?

回答

1

我認爲你的json變量有錯誤。您有:

"children": [{ 
    "data": "New node", 
    "id": "6", 
    "state":"open", 
    "children": [{ 
     "data": "New node 2", 
     "id": "7", 
     "state":"open", 
     "children": [{ }], 
    }], 
    "data": "kkk", 
    "id": "8", 
    "state":"open", 
    "children": [{ }], 
}], 

「children」數組中的每個節點必須分隔開{},並用逗號分隔。

+0

好吧,我看到在「data」處缺少一對「{}」:「kkk」,謝謝! – Gagiel

相關問題