使用linq to sql
流行的javascript树视图(jstree、dynatree…)是否可以设置为从邻接模型读取数据?假设我有一个带有classId、ClassName、ClassType、ParentClassId的表,我如何为dynatree获取数据?考虑到dyna树所期望的json应该在下面
{title: "Class1"},
{title: "Class2", isFolder: true,
children: [
{title: "Class4"},
{title: "Class5"}
]
},
{title: "Class3"}
我使用的是一个asp.net asmx web服务,在后端
要按需加载节点,唯一需要做的就是向其子节点将按需加载的节点添加"state":"closed"。
您可以将所有必要的属性classId, ClassName,ClassType,ParentClassId
附加到节点,这样您就可以通过ajax传递它。ur代码
"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')),
}
}
}
}