Get selected values from js tree without disabled

问题: I have js tree and some nodes are disabled. I want to get selected node values without disabled nodes. I used the following code to get selected node values, but it in...

问题:

I have js tree and some nodes are disabled. I want to get selected node values without disabled nodes.

enter image description here

I used the following code to get selected node values, but it includes disabled values too

$(document).on('click', '#users_perm_save', function (event) {
       var result = $('#jstree').jstree('get_selected'); 
    });

What will be the reason ?


回答1:

You can use Array filter method for that. Here is what you can do.

First get all the selected nodes and then filter it which is not disabled.

$(document).on('click', '#users_perm_save', function (event) {
   var result = $('#jstree').jstree('get_selected',true); 
  var checkedNodes = result.filter((node)=>{
    return node.state.disabled==false
  }).map((checked)=>{
    return checked.id
  });
   console.log(checkedNodes);
});
  • 发表于 2019-03-21 05:11
  • 阅读 ( 150 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除