How to select a specific node programmatically?

前端 未结 9 967
小鲜肉
小鲜肉 2021-02-02 07:18

I have a jstree. I want to select the node which is bound to the object which has a location with id of 158. This works but seems stupid. What\'s the more idiomatic way of doing

相关标签:
9条回答
  • 2021-02-02 07:53

    I did it with:

    $('.jstree').jstree(true).select_node('element id');
    

    this code:

    jQuery.each(produto.categorias, function(i, categoria) {
        $('#lista-categorias').jstree(true).select_node(categoria.dadoCategoria.id);
    });
    
    0 讨论(0)
  • 2021-02-02 07:59

    I was able to simulate a click on a jstree node as an alternative way to select a node. The following code is what was used :

    $(treeIdHandle + " li[id=" + nodeId + "] a").click();
    
    0 讨论(0)
  • 2021-02-02 07:59

    i think u should write code to select node after jstree initialized, therefore use this code

     $('#jstree')
        .on('ready.jstree', function (e, data) {
           // do function after jstree initialized
          $('#jstree')
            .jstree(true)
            .select_node('nodeid');
        });
    

    hope its work :)

    0 讨论(0)
提交回复
热议问题