get checked values for jsTree - submit with form post

前端 未结 11 1664
南笙
南笙 2020-12-14 02:40

I\'m using the jsTree jQuery plugin with the checkbox theme. Does anyone know how to get the selected values with a form post?

Thank you!

11条回答
  •  独厮守ぢ
    2020-12-14 03:18

    This I did:

    function getSelectedItems()
    {
        var checked_ids = [];
    
        checkedNodes = $("#MyTree").jstree("get_checked", null, true); 
    
        for(var i = 0; i < checkedNodes.length; i++)
        {
            var id = $(checkedNodes[i].outerHTML)[0].id;
    
            checked_ids.push(id);
        }
    
         // Do whatever you want with the checked_ids 
    }
    

    This will give you an array of all selected node and their sub nodes and leafs; as well as single leafs selected under other nodes.

提交回复
热议问题