2016-05-11 9 views
1

jstreeにチェックボックスがあります。 ノードを選択してボタンをクリックすると、そのノードの名前が取得されます。 しかし、私は各要素をjstreeに割り当てるために複数の選択を許可したいと思います。 選択したノードのc =値を取得する方法はありません。 また、その検索を許可したいのですが、それを行う方法がわかりません。jstreeから選択したチェックボックスを取得する

私はssearchプラグインを有効にしました。ここ はあなたが単純にチェックされているものを特定し、それを格納するためのチェックボックスを超える配列とループを宣言することができます私のコード

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
     <style> 
      html { margin:0; padding:0; font-size:62.5%; } 
      body { max-width:300px; min-width:100px; padding:20px 10px; font-size:14px; font-size:1.4em; } 
      h1 { font-size:1.8em; } 
      .demo { overflow:auto; border:1px solid silver; min-height:100px; } 
     </style> 
     <link rel="stylesheet" href="style.min.css" /> 
    </head> 
    <body> 
     <div id="frmt" class="demo"></div> 
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> 
     <script src="jstree.min.js"></script> 
     <button>>></button> 

     <script> 
      $('#html').jstree(); 
      $('#frmt').jstree({ 
       'core': { 
        'data':[{"id":"NODE 1","text":"node 1","children":[{"id","node 2","text":"node2"}]}] 
       }, 
       "checkbox" : { 
      "whole_node" : false, 
      "keep_selected_style" : true, 
      "three_state" : true, 
      "tie_selection" : false 
      }, "search" : { 
      "fuzzy" : true 
      },"plugins" : [ "checkbox", "search", "state", "wholerow", "types", "selectopens" ] 
      }); 
      $('#frmt').on("changed.jstree", function (e, data) { 
        console.log(data.selected); 
      }); 
      $('button').on('click', function() { 
       alert($('#frmt').jstree("get_selected")); 
      }); 
     </script> 

    </body> 
</html> 

答えて

1

あなたは

警告によってそれを得ることができます($( '#のFRMT')jstree( "get_checked"));

1

です。

var checked_ids = []; 
    $("#frmt").jstree("get_checked",null,true).each 
     (function() { 
      checked_ids.push(this.id); 
}); 
関連する問題