jsTree AJAX search with some node childs?

守給你的承諾、 提交于 2019-12-01 02:25:33

问题


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

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.

My SEARCH AJAX config:

        "search": {
        // search config
        "show_only_matches": true,
          'ajax': {
            'url': "/ajax/root-nodes"
          }
        },

jsSearch call:

$tree.jstree(true).search(searchText);

I also use lazy-loading of subnodes.

Is anybody do something like this?


回答1:


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

If for example your root node ID is "root1" use this:
$tree.jstree(true).search(searchText, false, true, '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

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"]



来源:https://stackoverflow.com/questions/31646186/jstree-ajax-search-with-some-node-childs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!