Jquery 用于动态创建jstree节点的有效json

Jquery 用于动态创建jstree节点的有效json,jquery,json,jquery-plugins,jstree,Jquery,Json,Jquery Plugins,Jstree,我有一个返回角色列表的方法,我想把这些角色放在jstree中,但我不知道怎么做 我尝试了以下操作,但我不知道如何为jstree生成有效的json function createNodeList() { $('#processRoleTree').jstree({ "json_data": { "ajax": { "type": "POST",

我有一个返回角色列表的方法,我想把这些角色放在jstree中,但我不知道怎么做

我尝试了以下操作,但我不知道如何为jstree生成有效的json

function createNodeList() {
        $('#processRoleTree').jstree({
            "json_data": {

                "ajax": {
                    "type": "POST",
                    "url": "/TreeLoader.aspx?Action=GetProcessRoles",
                    "dataType": "json",
                    "data": function (n) { return { id: n.attr ? n.attr("id") : 0} }

                }

            },
            "plugins": ["json_data", "themes", "ui"]


        }).bind("select_node.jstree", function (e, data) {
            var selectedObj = data.rslt.obj;
            alert(selectedObj.attr("id"));
        });
    }
在TreeLoader.aspx页面加载中,我有:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["Action"].Equals("GetProcessRoles"))

        {
            GetProcessRoles();
        }

    }
GetProcessRoles是我返回ProcessRole对象列表的方法

{ 
    "data" : "node_title", 
    // omit `attr` if not needed; the `attr` object gets passed to the jQuery `attr` function
    "attr" : { "id" : "node_identificator", "some-other-attribute" : "attribute_value" }, 
    // `state` and `children` are only used for NON-leaf nodes
    "state" : "closed", // or "open", defaults to "closed"
    "children" : [ /* an array of child nodes objects */ ]
}
如果您使用ajax从服务器获取json,请确保创建如下json结构

[
    { "data" : "A node", "children" : [ { "data" : "Only child", "state" : "closed" } ], "state" : "open" },
    "Ajax node"
]
有关详细信息,请参见此


好的,谢谢!只是我不知道在哪里还这个?!在我的GetProcessRole方法中???好的,我认为您的技术使用的是web服务,试着用c在asp中用json开发web服务#如果我使用ajax获取json,我们不能添加attr??