JsTree checkbox - check event

前端 未结 1 1019
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-20 10:32

I have this JsTree

with this code:

var Tree = $(\"#MyTree\");

        Tree.jstree({
            \"core\": {
                \"themes\": {
             


        
1条回答
  •  没有蜡笔的小新
    2021-02-20 11:17

    This answer is about the release 3 of jstree - that is what you should use in year 2016. Unfortunaltely your sample code, seems using jstree rel 1, and I can't help you about that.

    For release 3

    First of all, untie the selected and the checked states (checkbox.tie_selection: false) - see the docs

    Then, use the check_node.jstree event

    Working example

    var data1 = [{
          "id": "W",
          "text": "World",
          "state": { "opened": true },
          "children": [{"text": "Asia"}, 
                       {"text": "Africa"}, 
                       {"text": "Europe",
                        "state": { "opened": false },
                        "children": [ "France","Germany","UK" ]
          }]
        }];
    
    $('#Tree').jstree({ 
        core: {
          data: data1, 
          check_callback: false
        }, 
        checkbox: {       
          three_state : false, // to avoid that fact that checking a node also check others
          whole_node : false,  // to avoid checking the box just clicking the node 
          tie_selection : false // for checking without selecting and selecting without checking
        },
        plugins: ['checkbox']
    })
    .on("check_node.jstree uncheck_node.jstree", function(e, data) {
      alert(data.node.id + ' ' + data.node.text +
            (data.node.state.checked ? ' CHECKED': ' NOT CHECKED'))
    })
    
        
        
        

    0 讨论(0)
提交回复
热议问题