2016-06-14 9 views
0

特定のツリーに属するノードだけを選択させるルールを作成しようとしています。ユーザーは次のようにさまざまなレベルから複数のノードを選択するpossibilyあってはならない。JSTREEを使用して特定のツリー(レベル)に属するノードを選択する方法

the problem

あなたはどのようにそうするように任意のアイデアを持っていますか?

ありがとうございます。

+0

select_nodeイベントをリッスンし、選択したノードが他の選択されたノードと同じ親を持っているかどうかを確認する方法があります(簡単な方法があるかどうかはわかりません)...もし成功すれば投稿します答え – SpinaloS

答えて

0

、誰もが同じ問題に直面している場合、私は解決策を見つけた:

HTML部分:

<div id="jstree"/> 

javascriptの一部:

$(function() {$("#jstree").on("select_node.jstree", function (evt, data) { 

    var selectedNode= $('#jstree').jstree(true).get_selected(true); 

    for(var i = 0, j = selectedNode.length; i < j; i++) { 

    if(selectedNode.length > 1){ 

     var res = selectedNode[i].parents[selectedNode[i].parents.length-2]; 

     if(data.node.parent != res){ 
      $('#jstree').jstree("deselect_all"); 
     } 

    } 

    } 

}); 

$('#jstree').jstree({ 
    'core': { 

     'data': [{ 
      "id": "1.0", 
      "text": "Fresh Products", 
      "icon": "", 
      "state": { 
       "opened": false, 
       "disabled": false, 
       "selected": false 
      }, 
      "children": [{ 
       "id": "2.06.0", 
       "text": "Ethnic & Specialty", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": [{ 
       "id": "2.16.0", 
       "text": "Ethnic & Specialty", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": false, 
       "liAttributes": null, 
       "aAttributes": null 
      }, { 
       "id": "2.17.0", 
       "text": "Natural & Organic", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": false, 
       "liAttributes": null, 
       "aAttributes": null 
      }], 
       "liAttributes": null, 
       "aAttributes": null 
      }, { 
       "id": "2.07.0", 
       "text": "Natural & Organic", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": false, 
       "liAttributes": null, 
       "aAttributes": null 
      }, { 
       "id": "2.08.0", 
       "text": "Prepared Foods", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": false, 
       "liAttributes": null, 
       "aAttributes": null 
      }, { 
       "id": "2.09.0", 
       "text": "Seafood", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": false, 
       "liAttributes": null, 
       "aAttributes": null 
      }, { 
       "id": "2.010.0", 
       "text": "Seafood", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": false, 
       "liAttributes": null, 
       "aAttributes": null 
      }], 
      "liAttributes": null, 
      "aAttributes": null 
     }, { 
      "id": "2.0", 
      "text": "Frozen Products", 
      "icon": "", 
      "state": { 
       "opened": false, 
       "disabled": false, 
       "selected": false 
      }, 
      "children": [], 
      "liAttributes": null, 
      "aAttributes": null 
     }, { 
      "id": "3.0", 
      "text": "Store Equipment ", 
      "icon": "", 
      "state": { 
       "opened": false, 
       "disabled": false, 
       "selected": false 
      }, 
      "children": [], 
      "liAttributes": null, 
      "aAttributes": null 
     }, { 
      "id": "4.0", 
      "text": "Packaged Grocery", 
      "icon": "", 
      "state": { 
       "opened": false, 
       "disabled": false, 
       "selected": false 
      }, 
      "children": [], 
      "liAttributes": null, 
      "aAttributes": null 
     }, { 
      "id": "5.0", 
      "text": "Retail Technology", 
      "icon": "", 
      "state": { 
       "opened": false, 
       "disabled": false, 
       "selected": false 
      }, 
      "children": [], 
      "liAttributes": null, 
      "aAttributes": null 
     }, { 
      "id": "6.0", 
      "text": "HBC/Non-Foods", 
      "icon": "", 
      "state": { 
       "opened": false, 
       "disabled": false, 
       "selected": false 
      }, 
      "children": [{ 
       "id": "2.090.0", 
       "text": "Seafood", 
       "icon": "", 
       "state": { 
        "opened": false, 
        "disabled": false, 
        "selected": false 
       }, 
       "children": false, 
       "liAttributes": null, 
       "aAttributes": null 
      }], 
      "liAttributes": null, 
      "aAttributes": null 
     }] 



    }, 
    "search": { 

     "case_insensitive": true, 
     "show_only_matches" : true 


    }, 

    "plugins": ["search"] 


}); 

を});

関連する問題