如何以编程方式选择特定节点?

编程入门 行业动态 更新时间:2024-10-09 13:30:46
本文介绍了如何以编程方式选择特定节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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... });

更多推荐

如何以编程方式选择特定节点?

本文发布于:2023-11-05 02:57:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!