JQuery SimpleTree: add node programmatically

I'm trying to add a new node to jQuery SimpleTree , but all I can seem to get is "sTC.addNode is not a function" ...

var simpleTreeCollection = $('.simpleTree').simpleTree({
    animate:true,
    drag:false,
    autoclose: false,
    afterClick:function(node){},
    afterDblClick:function(node){},
    beforeMove:function (destination, source, pos){},
    afterMove:function(destination, source, pos){},
    afterAjax:function() {},
    afterContextMenu:function(node){}
});

simpleTreeCollection.addNode('test', 'test');

      

Any suggestions what I might be doing wrong? Is it possible to add a node?

0


source to share


4 answers


Maybe have a look at jsTree



+1


source


hmm tricky this this and I have to say that I don't like the plugin as it uses numeric values ​​as id and w3c states. "The attribute value must start with a letter in the range AZ or az, and may be followed by letters ......."

However, to get you to work, you need to first select one of the nodes to add to it, like this.



    //Select first child node in tree
    $('#2').click();
    //Add new node to selected node
    simpleTreeCollection.get(0).addNode(1,'A New Node')

      

+1


source


FYI the above code works in the firebug console on their demo page. On your tree, make sure you are using the correct selector to highlight the node

0


source


I solved this by editing the addNode function. I commented out temp_node.remove (); and added dragNode_destination.after (dragNode_source);

Just:

        TREE.addNode = function(id, text, callback)
        {
            var temp_node = $('<li><ul><li id="'+id+'"><span>'+text+'</span></li></ul></li>');
            TREE.setTreeNodes(temp_node);
            dragNode_destination = TREE.getSelected();
            dragNode_source = $('.doc-last',temp_node);
            TREE.moveNodeToFolder(dragNode_destination);
//          temp_node.remove();
            dragNode_destination.after(dragNode_source);
            if(typeof(callback) == 'function')
            {
                callback(dragNode_destination, dragNode_source);
            }
        };

      

0


source







All Articles