Javascript 在dynatree中混合使用多个选择(复选框)和单选(单选按钮)
我的dynatree看起来像这样:-Javascript 在dynatree中混合使用多个选择(复选框)和单选(单选按钮),javascript,jquery,dynatree,Javascript,Jquery,Dynatree,我的dynatree看起来像这样:- |---- Their Car |----------- Cars ----- |---- My Car | Objects ----------- |----------- Boats -----| --- My Boat
|---- Their Car
|----------- Cars ----- |---- My Car
|
Objects ----------- |----------- Boats -----| --- My Boat
| | --- Your Boat
| | --- custom1_Your Boat
| | --- custom2_Your Boat
|
|----------- Bikes1 -----| --- Your Bike
|----------- custom1_Bikes1 -----| --- My Bike
我希望用户能够在Bikes1
和custom1\u Bikes1
和Your Boat
,custom1\u Your Boat
和custom2\u Your Boat
中选择一个节点。其余节点应为多个可选节点
这是我到目前为止试过的
$(function(){
$("#tree").dynatree({
checkbox: true,
selectMode: 2,
initAjax: {
url: 'get-list.php'
},
onSelect: function(flag, node){
if (flag) {
var siblings = node.getParent().getChildren();
if((node.data.title).indexOf('custom') >= 0) { // If node contains the string 'custom'
for( var x in siblings) { // Loop through the sibling nodes
if(((node.data.title).split('_')[1] == x.data.title) || x.data.title.indexOf('custom') >= 0) { // Check if there is another node containing 'custom' or if there's a node with the same name after '_'
x.select(!flag); //deselect that node
}
}
}
else { // If the node doesn't contain the string 'custom'
for (var x in siblings) { // Loop through sibling
if((x.data.title).indexOf('custom') >= 0) { // Check if there is a node with string 'custom'
x.select(!flag); //deselect that node
}
}
}
}
}
// Do something else with the list of selected nodes
});
});
节点似乎没有被自动取消选择,我想知道
selectMode:2
是否覆盖了编程行为回答我自己的问题,问题在于我是如何循环通过兄弟节点的
以下是更正后的代码:
$(function(){
var inEventHandler = false;
$("#tree").dynatree({
checkbox: true,
selectMode: 2,
initAjax: {
url: 'get-list.php'
},
onSelect: function(select, dtnode) {
if (select) {
var siblings = dtnode.getParent().getChildren();
if((dtnode.data.title).indexOf('custom') >= 0) { //Check if it's a custom dtnode
for( var i = 0; i < siblings.length; i++) { // Loop through sibling nodes
if(((dtnode.data.title).split('_')[1] == siblings[i].data.title) || (siblings[i].data.title.indexOf('custom') >= 0 && siblings[i] != dtnode )) { // Check if there is another custom dtnode or base base dtnode
siblings[i].select(false); //deselect that dtnode
}
}
}
else {
for (var i = 0; i < siblings.length; i++) {
if((siblings[i].data.title).indexOf('custom') >= 0) { // Check if there is another custom dtnode
siblings[i].select(false);
}
}
}
}
// Do something with the selected nodes
}
});
});
$(函数(){
var inEventHandler=false;
$(“#树”).动态树({
复选框:正确,
选择模式:2,
initAjax:{
url:“get list.php”
},
onSelect:函数(select,dtnode){
如果(选择){
var sides=dtnode.getParent().getChildren();
if((dtnode.data.title).indexOf('custom')>=0){//检查它是否是自定义dtnode
对于(var i=0;i=0&&同级[i]!=dtnode)){//检查是否有其他自定义dtnode或基本dtnode
同级[i]。选择(false);//取消选择该dtnode
}
}
}
否则{
对于(变量i=0;i<1.length;i++){
if((同级[i].data.title).indexOf('custom')>=0){//检查是否有其他自定义dtnode
兄弟姐妹[i]。选择(false);
}
}
}
}
//对所选节点执行某些操作
}
});
});