2012-12-13 47 views
1

我想用EasyUI jquery tree。所以我创建了一个用于这个jQuery树的类。如何创建一个名为“checked”的属性?

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#" 
    }] 
}] 

MY MODEL

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; } 
} 

CONTROLLER(也许这不是neccesary)

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")。我怎样才能做到这一点。或者如果这是不可能的,另一种方法来实现我想要的。

谢谢。

回答

7

请使用:

public bool @checked { get; set; } 

checked是保留C#关键字。

+0

非常感谢。我会接受这一点。 –

+0

不客气! :) –

相关问题