如何以编程方式选择特定节点? [英] How to select a specific node programmatically?

查看:66
本文介绍了如何以编程方式选择特定节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个jstree.我想选择绑定到ID为158的对象的节点.此方法有效,但看起来很愚蠢.什么是更惯用的方式?

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 this?

var $tree = $('.jstree', myContext),
    node = $tree.find('li').filter(function() { 
        return ( $(this).data().location || {}).id === 158;
    });
$tree.jstree('select_node', n)

推荐答案

由于没有答案对我有用,所以只想在这里打电话.最终DID的工作非常简单:

Just wanted to chime in here as none of the answers worked for me. What finally DID work was very simple:

$('#someTree').jstree('select_node', 'someNodeId');

请注意,我没有将someNodeId初始化为jQuery对象.这只是一个普通的字符串.

Note that I didn't initialize someNodeId as a jQuery object. It's just a plain string.

我在没有加载树的情况下就这样做了( ),因为似乎没有必要,将其置于就绪"绑定事件中.

I did this right after a tree was loaded without putting it into a "ready" bind event as it seems to not be necessary.

希望它能从几个令人沮丧的时间中节省一些时间. .

Hope it saves some one from a few frustrating hours. . .

要在树被加载后挂接到树上:

To hook into the tree after it has been loaded:

.on('loaded.jstree', function() {
    // Do something here...
  });

这篇关于如何以编程方式选择特定节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆