jsTree AJAX搜索带有一些节点子节点? [英] jsTree AJAX search with some node childs?
问题描述
我尝试在jsTree中实现ajax搜索,但仅在根节点之一内部实现.
I try to implement ajax search in jsTree, but only inside one of root node.
我阅读了文档,发现了有关以下内容的信息:
I read docs, and found some info about:
$ .jstree.defaults.search.ajax
将在请求中添加一个str(即搜索字符串)参数,如果搜索仅限于节点ID,则会添加一个可选的inside参数.
A str (which is the search string) parameter will be added with the request, an optional inside parameter will be added if the search is limited to a node id.
我的SEARCH AJAX配置:
My SEARCH AJAX config:
"search": {
// search config
"show_only_matches": true,
'ajax': {
'url': "/ajax/root-nodes"
}
},
jsSearch呼叫:
jsSearch call:
$tree.jstree(true).search(searchText);
我还使用子节点的延迟加载.
I also use lazy-loading of subnodes.
有人在做这样的事情吗?
Is anybody do something like this?
推荐答案
在您的通话中,您并没有将搜索限制在特定的节点上:
http:///www.jstree.com/api/#/?q=search%28&f=search%28str%20[,%20skip_async]%29
In your call you are not limiting the search to a particular node:
http://www.jstree.com/api/#/?q=search%28&f=search%28str%20[,%20skip_async]%29
例如,如果您的根节点ID是"root1",请使用此命令:
$tree.jstree(true).search(searchText, false, true, 'root1');
If for example your root node ID is "root1" use this:
$tree.jstree(true).search(searchText, false, true, 'root1');
一旦调用search
函数,将根据您的配置发出AJAX请求.因此,在您的情况下,如果用户搜索"foo"
-这将是具有两个参数-str
和inside
的GET请求:
GET /ajax/root-nodes?str=foo&inside=root1
Once the search
function is invoked an AJAX request will be made as per your config. So in your case if the user searched for "foo"
- it will be a GET request with two params - str
and inside
:
GET /ajax/root-nodes?str=foo&inside=root1
您的响应应该是一个JSON数组,其中包含所有需要加载(和打开)的唯一父ID.您可能希望通过执行服务器端搜索,收集每个匹配项的父项,然后将它们组合到一个数组中(仅保留唯一的条目)来构建此数组:
["root1","somenode"]
Your response should be a JSON array, containing all the unique parent IDs that need to be loaded (and opened). You'd probably want to build this array by performing a server-side search, collecting the parents of each match, and then combining them in an array (and leaving only unique entries):
["root1","somenode"]
这篇关于jsTree AJAX搜索带有一些节点子节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!