我想使用EasyUI jquery tree。所以我创建了一个与这个 jquery 树一起使用的类。
Jquery 树数据格式示例
[{
"id":1,
"text":"Folder1",
"iconCls":"icon-save",
"children":[{
"text":"File1",
"checked":true
},{
"text":"Books",
"state":"open",
"attributes":{
"url":"/demo/book/abc",
"price":100
},
"children":[{
"text":"PhotoShop",
"checked":true
},{
"id": 8,
"text":"Sub Bookds",
"state":"closed"
}]
}]
},{
"text":"Languages",
"state":"closed",
"children":[{
"text":"Java"
},{
"text":"C#"
}]
}]
我的模特
public class MetersTreeNode
{
public int id { get; set; }
public string text { get; set; }
public string state { get; set; }
public bool checked { get; set; } //I cant define.
public string attributes { get; set; }
public ICollection<MetersTreeNode> children { get; set; }
}
控制器(也许这不是必需的)
public ActionResult GetDemoTree()
{
var result = new[]
{
new MetersTreeNode{
id = 0,
text = "level 1",
state = "open",
attributes = "",
children = new[]{
new MetersTreeNode{
id=1,
text="level 2",
state="open",
attributes=""
},
new MetersTreeNode{
id=2,
text="level 2",
state="open",
attributes="",
children = new []{
new MetersTreeNode{
id=5,
text="level 3",
state="open",
attributes=""
}
}
},
new MetersTreeNode{
id=3,
text="level 2",
state="open",
attributes=""
},
new MetersTreeNode{
id=4,
text="level 2",
state="open",
attributes=""
}
}
}
};
return Json(result, JsonRequestBehavior.AllowGet);
}
使用checked
参数。我应该在我的模型中定义它。但我无法定义它。(Error :"invalid token 'checked' in class struct or interface member declaration")
. 我怎样才能做到这一点。或者,如果不可能,另一种方式来实现我想要的。
谢谢。