2014-11-24 93 views
0

我得到了这个问题,即时通讯工作与asp和jstree复选框插件,我需要得到比选定的所有节点(父母与他的孩子),首选完整路径阵列然后分裂它,因为我需要做一个数据库搜索,我需要父母和孩子。ASP.NET jstree复选框得到所有选定的节点和子节点

这是我的代码:

<!DOCTYPE html> 
 

 
<html xmlns="http://www.w3.org/1999/xhtml"> 
 
<head runat="server"> 
 
    <title></title> 
 

 
    <link href="jstree-bootstrap-theme-master/dist/libs/bootstrap/css/bootstrap-theme.min.css" rel="stylesheet" /> 
 
    <link href="jstree-bootstrap-theme-master/dist/libs/bootstrap/css/bootstrap.min.css" rel="stylesheet" /> 
 

 
    <link href="jstree-bootstrap-theme-master/dist/themes/proton/style.min.css" rel="stylesheet" /> 
 

 
    <script src="https://code.jquery.com/jquery-1.11.0.min.js"></script> 
 
    <script src="jstree-bootstrap-theme-master/dist/libs/bootstrap/js/bootstrap.min.js"></script> 
 
    <script src="jstree-bootstrap-theme-master/dist/jstree.min.js"></script> 
 
    
 
</head> 
 
<body> 
 

 
    <div id="container"> 
 
     <ul> 
 
      <li>Root node 
 
     <ul> 
 
      <li id="child_node">Child node</li> 
 
     </ul> 
 
      </li> 
 
     </ul> 
 
    </div> 
 

 
    <button type="button" class="btn btn-primary" id="getChecked">Botón normal</button> 
 
    
 

 

 

 

 
    <script type="text/javascript"> 
 
     $('#container').jstree({ 
 
      'plugins': ["wholerow", "checkbox"], 
 
      'core': { 
 
       'data': [{ 
 
        "text": "RRRAAAA", 
 
        "children": [ 
 
         { 
 
          "text": "S1", 
 
          "icon": "glyphicon glyphicon-chevron-right", 
 
          "state": { 
 
           "selected": false 
 
          } 
 
         }, 
 
        { 
 
         "text": "S2", 
 
         "icon": "glyphicon glyphicon-chevron-right" 
 
        }, 
 
        { 
 
         "text": "A2", 
 
         "icon": "glyphicon glyphicon-chevron-right" 
 
        }, 
 
        { 
 
         "text": "A2", 
 
         "icon": "glyphicon glyphicon-chevron-right" 
 
        }, 
 
        { 
 
         "text": "F", 
 
         "icon": "glyphicon glyphicon-chevron-right" 
 
        }] 
 
       }], 
 
       'themes': { 
 
        'name': 'proton', 
 
        'responsive': true 
 
       } 
 
      } 
 
     }).on('select_node.jstree', function (e, data) { 
 
     var i, j, nid; 
 

 
     for (i = 0, j = data.selected.length; i < j; i++) { 
 
      nid = data.instance.get_node(data.selected[i]).id; 
 

 
      alert(nid); 
 

 
     } 
 
    }); 
 
     
 
     
 
     
 

 
     $(function() { 
 

 
      $("#getChecked").click(function() { 
 

 
       $("#tree").jstree("get_checked", null, true).each(function (i, e) { 
 
        console.log($(this).attr("id")); 
 
        alert($(this).attr("id")); 
 
       }); 
 
      }); 
 

 
     }); 
 
    </script> 
 

 
</body> 
 
</html>

回答

0

在Jstree有可用于检查节点和未选中状态之间进行区分2类。他们是“jstree核对”分别

“jstree,选中”因此,为了得到所有这些都选中,您可以使用下面的逻辑

var nodeCheckedCount= $('.jstree-unchecked').length;  
var Ids = ''; 
     if (nodeCheckedCount= > 0) { 
      for (i = 0; i < nodeCheckedCount= ; i++) { 
       var temp = $($('.jstree-unchecked')[i]).attr('id') 
       if (Ids == "") { 
        Ids += temp; 
       } 
       else { 
        Ids= Ids + "," + temp; 
       } 
      } 
console.log(Ids) 
-1

其实这个代码工作的节点,而不是我想要什么,我需要全路径,但我需要获取所有节点时,我点击一个按钮。 在这段代码中,我遇到了一个麻烦,因为当检查一个父节点时,向我显示了警报,但没有显示所有子节点的完整路径,只是重复显示多次警报而没有显示完整路径;当我检查每个节点的manully时,完整的路径有效。

.on('select_node.jstree', function (e, data) { 
     var selectedNodes = $('#container').jstree(true).get_selected(); 
     for (var node in selectedNodes) { 
      var path = $('#container').jstree(true).get_path(data.node, "/"); 
      alert(path); 
     }   
    }); 
+0

它不工作:( – 2016-04-11 14:02:47

相关问题