带有自定义 json 数据的 JsTree

2024-04-24

我在 json 中有这个结构,无法根据请求进行修改。

{
        "Object": [
            {
                "url": "http://www.google.com"
            }            
        ],
        "id": 1,
        "name": "Redirection Rule",
        "Object": {
            "frequency": 1,
            "trigger": 1
        },
        "Object": {
            "http": "Redirect Url",
            "response": 301
        }
    }

我需要使用这个结构来填充 jstree 。我只需要使用“id”字段和“name”,如何设置jstree使用“name”而不是“text”作为节点名称?


Either:

1)使用jQuerydataFilter选项(这意味着定义一个函数dataFilter在你的core.datajsTree 配置),

or

2) set core.data本身为一个函数,手动发出请求并像这样转换它:

$('#your-tree').jstree({
    core : {
        data : function (node, cb) {
            $.ajax({ url : ... }).done(function (data) {
                cb([{ "id" : data.id, "text" : data.name }])
            });
        }, ...

您可以找到有关设置的更多信息core.data到这里的一个函数:https://github.com/vakata/jstree#populate-the-tree-using-a-callback-function https://github.com/vakata/jstree#populating-the-tree-using-a-callback-function

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

带有自定义 json 数据的 JsTree 的相关文章

随机推荐