public class TreeNode
{
public string text;
public string id;
public string href;
public bool leaf;
public List<TreeNode> children;
public bool checked; //出错
}
我需要得到一个json
/// <summary>
/// 创建父菜单下拉列表
/// </summary>
/// <param name = "ParentID"></param>
public ActionResult ComboTree()
{
IList<MenuPermission> modelList = Bll.GetAll();
List<TreeNode> TreeNode = new List<TreeNode>();
TreeNode = GetTree(null, modelList,false);
return this.Json(TreeNode, JsonRequestBehavior.AllowGet);
}
private static List<TreeNode> GetTree(string PID, IList<MenuPermission> modelList, bool type)
{
List<TreeNode> treeNode = new List<TreeNode>();
foreach (MenuPermission model in modelList)
{
if (PID == model.ParentID)
{
TreeNode treeModel = new TreeNode();
treeModel.id = model.ID.ToString();
treeModel.text = model.Name;
if (type)
{
treeModel.href = model.URL;
}
treeModel.children = GetTree(model.ID.ToString(), modelList, type);
if (treeModel.children.Count == 0)
treeModel.leaf = true;
else
treeModel.leaf = false;
treeModel.checked = false;
treeNode.Add(treeModel);
}
}
return treeNode;
}
页面上需要这个checked不知道应该怎么解决?
------解决方案--------------------------------------------------------
你为这个蛋疼只说明你不好好看书不认真看文档...
方法有三...
1.大写...Checked...
2.加@...@checked...
但是...这两个其实跟你的问题没关系...
3.指定序列化成员名称...
[DataMember(Name = "checked")]
public bool IsChecked;