3

可以设置流行的 javascript 树视图(jstree、dynatree ...)以从邻接模型中读取数据吗?假设我有一个带有 classId、ClassName、ClassType、ParentClassId 的表,我如何获取数据来表示 dynatree?考虑到 dyna 树所期望的 json 应该如下所示

        {title: "Class1"},
        {title: "Class2", isFolder: true,
            children: [
                {title: "Class4"},
                {title: "Class5"}
            ]
        },
        {title: "Class3"}

我在后端使用带有 linq to sql 的 asp.net asmx Web 服务

4

1 回答 1

2

要按需加载节点,您唯一需要做的就是将“状态”:“关闭”添加到其子节点将按需加载的节点。

您可以将所有必要的属性classId, ClassName,ClassType,ParentClassId附加到节点,然后您可以通过 ajax 传递它。你的代码

"json_data": {
      //elements to be displayed on the first load
      //everything with state = closed will be populated via ajax. 
      //         Note the ajax arguments

    "data": [{"data":'Class 1',
              "attr":{"id":'kit1',
                      "ClassName":"ClassName",
                      "classId":"classId"},
              "state" : "closed"},
             {"data":'Class 2',
              "attr":{"id":'kit2',
                      "ClassName":"ClassName",
                      "classId":"classId"},
              "state" : "closed"}
            ],
    "ajax" : {
        url : "http://localhost/introspection/introspection/product",
        data : function(n) {
                 return {
                   "classId":$.trim(n.attr('classId')),
                   "ClassName":$.trim(n.attr('ClassName')),
                 }
               }
    }
 }
于 2012-01-26T22:14:03.060 回答