jsTree异步搜索-触发加载新节点 [英] jsTree asynchronous search - trigger load new nodes

查看:238
本文介绍了jsTree异步搜索-触发加载新节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的一个项目上运行了一个运行良好的jsTree实现. JSON数据由PHP/Ajax提供.使用搜索插件时遇到了麻烦.

I have a nicely running implementation of jsTree running on a project of mine. The JSON data is provided by PHP/Ajax. I've run into some trouble while using the search plugin.

jsTree的搜索插件文档说:

因此,在您的响应中,您必须以id形式返回节点的路径(不包含节点本身):["#root_node",#child_node_3"]

so in your response you must return the path to the node (without the node itself) as ids: ["#root_node","#child_node_3"]

...因此,我的服务器端搜索功能正在将路径返回到匹配的节点,就像这样(是的,我正在json_encode对其进行访问):

...so, my server side search function is returning a path to the matched node like so (yes, I'm json_encodeing it):

Array( '#1', '#2', '#3', '#5' ); // to match node #10 (leaf node) at the end

当这些值已经存在于DOM中时,客户端搜索功能可以正常工作,但是当元素不存在时,我无法让jsTree遵循此数组(或多个数组)中提供的路由来填充树存在(例如,仅当根节点处于打开状态时).

When these values already exist in the DOM, the client side search functionality works fine, but I am having trouble getting jsTree to follow the route provided in this array (or arrays) to populate the trees when the elements don't already exist (e.g. when only the root node is open).

我在Stack上看到了与此类似的问题,但是没有一个答案.我要重新发布,因为我需要了解它是如何工作的,并且在搜索插件文档之外没有找到太多有关如何将jsTree与异步搜索一起使用的信息.

I have seen similar questions to this on Stack, but none have any answers. I'm re-posting because I need to understand how this works and haven't found much information past the search plugin docs about how to use jsTree with asynchronous searching.

基本上我想要做的是使用搜索函数返回的数组来触发jsTree的加载事件(类似于load_node_json之类的东西)-我认为这应该可以直接使用,但是我已经麻烦了.我几乎只是插入了jsTree文档中的示例代码.

Essentially what I want it to do is use the array my search function returns to trigger jsTree's loading event (something like load_node_json) - I would've figured that this should work straight out of the box but I'm having trouble with it. I've pretty much just plugged in the example code from the jsTree documentation.

推荐答案

我已经弄清楚了.我的问题是我要返回多个包含每个匹配节点路径的数组,如下所示:

I've figured this out. My problem was that I was returning multiple arrays containing the path to each matched node like this:

Array(
    Array('#root', '#child', '#sub-child'),
    Array('#root', '#child', '#second-sub')
)

事实证明,jsTree的搜索插件 A 仅需要一个单层数组,而 B 将加载该数组中列出的所有节点,路径顺序不不必像文档中所建议的那样完全准确.

As it turns out, jsTree's search plugin A only expects a single-level array, and B will load all nodes listed in that array, the path order doesn't have to be perfectly accurate like the documentation might suggest.

因此,相反,在我的JSON中,我返回了一个包含唯一节点ID的数组,如下所示:

So instead, in my JSON I'm returning an array containing unique node IDs like this:

Array( '#root', '#child', '#sub-child', '#second-sub' )

...并且搜索插件正在按预期加载节点.

...and the search plugin is loading the nodes as expected.

最后没什么花哨的,但是我认为jsTree文档应该对此事更具描述性,因为我看到其他人也遇到同样的问题而没有答案.

Nothing fancy in the end, but I think the jsTree documentation should be more descriptive on this matter as I've seen others with the same problem and no answers.

这篇关于jsTree异步搜索-触发加载新节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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