我尝试在jsTree中实现ajax搜索,但只在一个根节点内实现.
我阅读了文档,并找到了一些信息:
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.
我的搜索AJAX配置:
"search": { // search config "show_only_matches": true,'ajax': { 'url': "/ajax/root-nodes" } },
jsSearch电话:
$tree.jstree(true).search(searchText);
我也使用延迟加载子节点.
有人做过这样的事吗?
解决方法
在您的通话中,您不会将搜索限制在特定节点:
http://www.jstree.com/api/#/?q=search%28&f=search%28str%20[,%20skip_async]%29
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′);
调用搜索功能后,将根据您的配置发出AJAX请求.因此,在您的情况下,如果用户搜索“foo” – 它将是一个带有两个参数的GET请求 – str和inside:
GET / ajax / root-nodes?str = foo& inside = root1
您的响应应该是一个JSON数组,包含需要加载(和打开)的所有唯一父ID.您可能希望通过执行服务器端搜索来构建此数组,收集每个匹配的父项,然后将它们组合在一个数组中(并且只保留唯一条目):[中 “root1”,“somenode”]