繁体   English   中英

jsTree JSON解析问题

[英]jsTree JSON parse issue

我使用JSTree插件显示部门限制。 Serverside(asp.net 3.5)运行良好,并且我得到了JSON对象。

但是当我尝试:

$(document).ready(function () {
    $('#btntst').click(function () {
        $('#mainDiv').html('wait for data');
        $.ajax({
            type: 'POST',
            url: '_layouts/GridView/ApplicationPage1.aspx/getTable',
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            data: "{}",
            success: function (msg) {
                $('#jsTreeContainer').jstree({
                    "json_data": {
                        "data": [msg.d]
                    }
                    , "plugins": ["themes", "json_data"]
                });
            }
            , timeout: 60000
        });
    });

});

我只有一个带有所有JSON字符串的节点。
JSON字符串,由webmethod返回:

{
  'data': 'department001',
  'attr': {
    'id': 'nodeid1773'
  },
  'children': [

  ]
},
{
  'data': 'department001',
  'attr': {
    'id': 'nodeid1779'
  },
  'children': [

  ]
}

如果我将此字符串复制粘贴到:

"json_data": {"data" : [...] }

我得到正确的结果。 请帮助,不能理解我在做什么错。

您的脚本正在寻找json_data类型的JSON对象,但通常的响应只是data 查看这些更改是否有效:

$(document).ready(function () {
    $('#btntst').click(function () {
        $('#mainDiv').html('wait for data');
        $.ajax({
            type: 'POST',
            url: '_layouts/GridView/ApplicationPage1.aspx/getTable',
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            data: "{}",
            success: function (msg) {
                $('#jsTreeContainer').jstree({
                    "json_data": [msg.d],
                    "plugins": ["themes", "json_data"]
                });
            }
            , timeout: 60000
        });
    });

});

暂无
暂无

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

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