jsTree search with Ajax/JSON not calling URL

▼魔方 西西 提交于 2019-12-01 17:53:42
Robbie Averill

Did you get a solution in the end?

I'm doing the same thing at the moment - the ajax section of the search plugin options behaves just like jQuery ajax options, for me I specified type: "POST", a success function and dataType: "JSON" and my success function is recording the results in my console.

From the manual (not the best manual in the world), for each search result matched, you need to specify the path to it without including the matching nodes ID. jsTree will then load the path you give it and the inbuilt highlighting will match the text. E.g. if the entry your search matched is in the #secondchild node (3 levels down), this is what you'll need to pass to jsTree for it to load that result in your search:

Array[ '#rootnode', '#firstchild', '#secondchild' ]

This will load those three nodes with the standard data retrieval method you've specified already, if they don't already exist in the DOM. Do a few tests with your JSON results by hard coding the path you're after to see how it works.

Note: if you've defined a success method in your Ajax request, you'll need to return the data object you get in your method, which will allow jsTree to parse it and do its thing. In my case I had console.log(data) and it did nothing, because I wasn't returning the data afterwards.

EDIT

I solved my problem, instead of returning multiple arrays containing the path to each matched element you need to return a single-level array containing the unique node IDs, and the search plugin parses it as expected and loads the new ones before the client side search is performed.

See here for my explanation: https://stackoverflow.com/a/20316921/2812842

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