3

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

CONTROLLER (これは必要ないかもしれません)

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"). これどうやってするの。または、それが不可能な場合は、私が望むものを達成する別の方法です。

ありがとう。

4

1 に答える 1

9

使ってください:

public bool @checked { get; set; }

checkedは予約済みの C# キーワードです。

于 2012-12-13T14:49:27.767 に答える