Search code examples
javascriptphpjqueryjqtree

jqtree cant load data with loadDataFromUrl function


so here is my code

$('#parent').bind(
    'tree.click',
    function(event) {
        // The clicked node is 'event.node'
        var node = event.node;
        $('#parent').tree('loadDataFromUrl', 'g/admin/rules/getchildstwo/id/' + node.id, node,
            function() {
                alert('data is loaded');
            }
        );

        $('#parenthide').val(node.id);
    }
);

but callback function is not called and subtree is not loaded into node..i tried and loaded data seperatly with ajax and result is somthing like this:

{
    label: 'تست سمپل',
    id: 2540,
    section: '1',
    children: []
},


{
    label: 'hshhsh',
    id: 2541,
    section: '1',
    children: []
}

but still loadDataFromUrl not working and filling subtree..can anyone tell me whats wrong with my code or show me a working examlple of loading subtree wuth JQTree?


Solution

  • Try like this

    var data = [
        {
            label: 'تست سمپل', id: 2540,
            section:  '1',
            children: []
        },
        {
            label: 'hshhsh', id: 2541,
            section:  '1',
            children: []},
        }
    ];
    
    
    $('#parent').tree({
       dataUrl: 'loadDataFromUrl',
      function() {
                alert('data is loaded');
            }
    });