Programmatically adding child nodes to a jstree

被刻印的时光 ゝ 提交于 2019-12-04 00:18:55

When using periods in ID's you need to escape them like so:

$("#tree").jstree("create", $("#child1\\.id"), "inside",  { "data" : "child2" },
                          function() { alert("added"); }, true);

This is because of how it uses jQuery selectors. It is mentioned in the jsTree FAQ located here: http://www.jstree.com/faq/

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 );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!