具有自定义json数据的JsTree [英] JsTree with custom json data

查看:383
本文介绍了具有自定义json数据的JsTree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在json中有此结构,无法通过请求进行修改.

I have this structure in json I can not be modified by request.

{
        "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"作为节点名称?

I need to use this structure to populate a jstree . I just need to use the "id" fields and "name", how do I set jstree to use "name" instead of "text" as a node name ?

推荐答案

任一:

1)使用jQuery dataFilter选项(这意味着在core.data jsTree配置中为dataFilter定义一个函数),

1) use the jQuery dataFilter option (this means defining a function for dataFilter in your core.data jsTree config),

2)将core.data本身设置为函数,手动发出请求并将其转换为:

2) set core.data itself to a function, manually make the request and transform it like so:

$('#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#populating树使用回调函数

You can find more info on setting core.data to a function here: https://github.com/vakata/jstree#populating-the-tree-using-a-callback-function

这篇关于具有自定义json数据的JsTree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆