2012-12-13 46 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

不客氣! :) –

相關問題