2016-07-25 151 views
0

我正在使用jsTree。我想限制子節點的選擇爲4(要麼不允許用戶選擇多於4個節點,要麼禁用所有的複選框)。我正在使用選擇限制,這是行不通的。我怎樣才能做到這一點?限制在jstree中選擇子節點的數量

$("#mytree").jstree({ 
    "plugins" : [ "themes","html_data", "ui", "crrm","checkbox" ], 
    "html_data" : { 
     // ... 
    }, 
    "checkbox": { 
     "keep_selected_style": false 
    }, 
    "ui": { 
     "select_limit": 4, 
    }, 
    // ... 
}); 
+1

[jstree select \ _limit不能正常工作。我想設置選擇限制來選擇只有3個節點](http://stackoverflow.com/questions/14785236/jstree-select-limit-not-working-i-want-to-set-selection-limit-to-select -only-3) –

+0

你檢查過了嗎? http://stackoverflow.com/questions/14785236/jstree-select-limit-not-working-i-want-to-set-selection-limit-to-select-only-3 –

+0

是的,我試過這個。不工作 – Nagendra

回答

0

在用常規方法,你可以得到這個任務完成如下

var children = document.getElementById("mytree").children; 
var limit = 4; 
for (var i = 0; i < limit; ++i) 
{ 
    if (!children[i]) return; 
    children[i].classList.add("off"); 
} 
+0

我試過上面的代碼。我可以選擇4個以上的節點。 – Nagendra

+0

不,它不工作。正如我所說我能夠選擇多於4個節點,我只需要最多選擇4個節點,如果用戶嘗試選擇另一個節點,則不應該選擇該節點 – Nagendra

+0

您是否已將這段代碼放在' ui:'屬性spec部分還是創建了一個JS方法並調用它? –