Programmatically adding child nodes to a jstree

前端 未结 2 805
暖寄归人
暖寄归人 2021-02-19 15:12

I\'m trying to write some code that adds nodes to a jstree dynamically. I\'ve followed the doc at http://www.jstree.com/documentation/crrm but can\'t get a simple example to wor

2条回答
  •  滥情空心
    2021-02-19 15:33

    first initialize jstree(in my case i use ajax), put check_callback into core obj and call the plugin after core obj like this:

    jQuery('#jstree_demo_div').jstree({
        'core' : {
              'data' : {
                'url' : 'data/mapas.php',
    
              },
              "check_callback" : function(e,data){
                  console.log(data)
              }
          },
          "plugins" : [ "contextmenu" ] })
    

    second use this line and put $('#j1_1') as parent , the data in json, 'last' as position or 'first', the function callback (in my case is the function tales()), internal argument set in true

    jQuery("#jstree_demo_div").jstree(true).create_node( $('#j1_1'), {text: "New node", id: true} , "last",tales(), true );
    

提交回复
热议问题