我有一个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... });更多推荐
如何以编程方式选择特定节点?
发布评论