get checked values for jsTree - submit with form post

前端 未结 11 1642
南笙
南笙 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:14

    The suggested solution from google groups however didn't work for partially checked nodes, in my case. I had to leave the get_checked out and do the following to get fully selected and partially selected nodes.

    $(".sector-tree").find(".jstree-undetermined").each(function(i,element){ checked_ids.push($(element).attr("id")); if ($(this).find(".jstree-undetermined").length == 0) { $(this).find(".jstree-checked").each(function(i, element){ checked_ids.push({$(element).attr("id")); }); } }); // collect the rest of the checked nodes that exist under checked parents $(".sector-tree").find(".jstree-checked").each(function(i, element){ //also includes the ones below 'undetermined' parent var selectedElement = $(element).attr("id"); if ( hasItem(selectedElement, checked_ids ) < 0 ) { checked_ids.push(selectedElement); } });
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-14 03:21

    You can use this:

    var result = $('#your_tree').jstree('get_selected');
    

    https://stackoverflow.com/a/22499278/1883345

    0 讨论(0)
  • 2020-12-14 03:21

    i did this to get id,parentid and text of selected checkbox. hopefully it will help someone :)

    function myFunction(elmnt,clr){
             elmnt.style.color =clr;
             var selectedElmsinfo = [];
    
             var selectedElms = $('#SimpleJSTree').jstree("get_selected", true);
                $.each(selectedElms, function() {
                    selectedElmsinfo.push(this.id,this.text,this.parent);
    
                });
                 alert(selectedElmsinfo);
            }
    
    0 讨论(0)
  • 2020-12-14 03:22

    Everyone, who worked with Jstree’s may face to this question: How to get the checked Ids of Jstree in form submit? here is the solution:

    function submitMe() {
        var checked_ids = [];
        $('#your-tree-id').jstree("get_checked",null,true).each(function(){
            checked_ids.push(this.id);
        });
        //setting to hidden field
        document.getElementById('jsfields').value = checked_ids.join(",");
    }
    

    Now, we set it in a hidden field:

    <input type="hidden" name="jsfields" id="jsfields" value="" />
    
    0 讨论(0)
提交回复
热议问题