2012-09-28 117 views
1

我目前正在研究django項目,並使用dynatree構建treeview。 我有兩棵樹,第一棵樹有用戶可以選擇的項目,選定的項目將移動到第二棵樹。有沒有一種方法可以在dynatree中做到這一點?用戶可以選擇「取消選擇」該項目,以便所選項目移回第一個樹。所以當用戶取消選擇項目時,我如何將項目移回其原始父節點?在此先感謝..使用Dynatree將節點從一棵樹移動到另一棵

+0

歡迎來到Stack Overflow!我們鼓勵你[研究你的問題](http://stackoverflow.com/questions/how-to-ask)。如果你已經[嘗試了某些東西](http://whathaveyoutried.com/),請將其添加到問題中 - 如果沒有,請先研究並嘗試您的問題,然後再回來。 – 2012-09-28 09:03:15

回答

2

我已經使用複製/粘貼上下文菜單的概念。 而對於第二個問題,我使用全局變量來存儲原始父節點,因此當用戶取消選擇該項目時,它將回到其原始父級。

+0

你能分享一些代碼嗎? – saTech

+0

您好@saTech,下面的代碼是我用來dynatrees之間傳輸節點: '函數transferNodes(節點,sourceNode){風險copyNode = sourceNode.toDict(真,函數(字典){ \t \t \t dict.title = dict.title; \t \t \t delete dict.key; \t \t}); \t \t node.addChild(copyNode); \t \t sourceNode.remove(); \t}' 我在dynatree的contextMenu中調用函數。 – kyiphyu

0

'selected'和'active'之間有區別。 選擇通常使用複選框來完成,而只有一個節點可以被激活(通常通過鼠標點擊)。 第二次點擊活動節點不會觸發'onActivate'事件,但您可以實現'onClick'處理程序來捕獲並調用node.deactivate()

1

我有一個DIV的dvAllLetterTemplates(其中包含一個主列表)和一個DIV dvUserLetterTemplates的項目將被複制到dynamTree。


//Select the Parent Node of the Destination Tree 
var catNode = $("#dvUserLetterTemplates").dynatree("getTree").selectKey(catKey, false); 
if (catNode != null) { 
//Select the source node from the Source Tree 
    var tmplNode = $("#dvAllLetterTemplates").dynatree("getTree").selectKey(arrKeys[i], false); 
    if (tmplNode != null) { 
     //Make a copy of the source node 
     var ndCopy = tmplNode.toDict(false, null); 
     //Add it to the parent node 
     catNode.addChild(ndCopy); 
     //Remove the source node from the source tree (to prevent duplicate copies 
     tmplNode.remove(); 
     //Refresh both trees 
     $("#dvUserLetterTemplates").dynatree("getTree").redraw(); 
     $("#dvAllLetterTemplates").dynatree("getTree").redraw(); 
    } 
} 
 
+0

嗨@vishnoo我已經解決了我的問題,但謝謝你的答案。 – kyiphyu