简体   繁体   English

带有Ajax调用/延迟加载的JSTree搜索

[英]JSTree Search with Ajax Call / Lazy Loading

I am using JSTree in my application. 我在应用程序中使用JSTree。

I am unable to implement Search functionality with ajax call. 我无法通过ajax调用实现搜索功能。

Here i am putting what i tried. 在这里,我把我尝试过的。

$(document).ready(function () {
    $("#jstree_demo_div").jstree({
        "core": {
            "data": {
                "url": "Tree/Index",
                "data": function (node) {
                    return { "id": node.id };
                }
            }
        },
        "search": {
            "url": "Tree/Index",
            "data": function (node) {
                return { "id": node };
            }
        },
        "plugins": ["search"],
    });

    $('#searchTree').on('click', function (event) {
        $("#jstree_demo_div").jstree('search', '1');
    });
});

Whenever i press button it comes to event and after that call is not made to server. 每当我按下按钮时,就会发生事件,之后不会再向服务器发出呼叫。

What i want is to make ajax call on search and completely recreate treeview as per search. 我想要的是在搜索上进行ajax调用,并根据搜索完全重新创建treeview。

I am unable to understand how can i do this? 我不明白该怎么办?

I already checked following link. 我已经检查了以下链接。

JSTree API Documentation JSTree API文档

jsTree search with Ajax/JSON not calling URL 使用Ajax / JSON的jsTree搜索未调用URL

In above stackoverflow question i am unable to understand what is "json_data" and why and how it is used? 在上面的stackoverflow问题中,我无法理解什么是“ json_data”以及为什么以及如何使用它?

There is not a single example in https://www.jstree.com that uses variable like named "json_data". https://www.jstree.com中没有一个示例使用名为“ json_data”的变量。

Please help me to understand how JSTree Ajax call / Lazy Loading works with search functionality with example. 请帮助我了解JSTree Ajax调用/延迟加载如何与示例一起使用搜索功能。

在此处输入图片说明

This is really helpful for me. 这对我真的很有帮助。 Thank you in advance. 先感谢您。

The search.ajax.data config option can not be a function - it should be an object (just like a normal jQuery AJAX config), jstree will only add a str property to that object. search.ajax.data配置选项不能是一个函数-它应该是一个对象(就像普通的jQuery AJAX配置一样),jstree只会向该对象添加str属性。 As for GET or POST - use whichever you want - all you need to specify as search.ajax is a valid jQuery AJAX config. 至于GET或POST-使用任何您想要的-您需要指定为search.ajax都是有效的jQuery AJAX配置。

Change search settings to : search设置更改为:

"search": {
    "ajax": {
         "url": url,
            }
          },

Your search configuration need to correct, to search with a keyword you need to pass the keyword to your url and You should use GET method to retrive data. 您的搜索配置需要更正,要使用关键字进行搜索,您需要将关键字传递给url,并且应该使用GET方法来检索数据。 Try this 尝试这个

        // Configuring the search plugin
        "search" : {
            // As this has been a common question - async search
            // Same as above - the `ajax` config option is actually jQuery's AJAX object
            "ajax" : {
                "url" : "Tree/Search",
                // You get the search string as a parameter
                "data" : function (str) {
                    return { 
                        "operation" : "search", 
                        "q" : str 
                    }; 
                }
            }
        },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM