ExtJs菜单从数据库绑定

时间:2011-05-17 13:45:31

标签: extjs

请提供一些示例代码或想法,如何从Json结果动态绑定菜单 我从json获得了数据库的结果,所以如何从json(父和子)

绑定菜单

提前致谢

1 个答案:

答案 0 :(得分:1)

实际上非常简单。当您从服务器返回数据时,您需要做的就是在JSON中包含一个metaData字段,用于定义记录结构。

请参阅此文档:http://dev.sencha.com/deploy/ext-3.3.1/docs/?class=Ext.data.JsonReader

文档中的示例如下:

{

    metaData: {
        "idProperty": "id",
        "root": "rows",
        "totalProperty": "results"
        "successProperty": "success",
        "fields": [
            {"name": "name"},
            {"name": "job", "mapping": "occupation"}
        ],
        // used by store to set its sortInfo
        "sortInfo":{
           "field": "name",
           "direction": "ASC"
        },
        // paging data (if applicable)
        "start": 0,
        "limit": 2,
        // custom property
        "foo": "bar"
    },
    // Reader's configured successProperty
    "success": true,
    // Reader's configured totalProperty
    "results": 2000,
    // Reader's configured root
    // (this data simulates 2 results per page)
    "rows": [ // *Note: this must be an Array
        { "id": 1, "name": "Bill", "occupation": "Gardener" },
        { "id": 2, "name":  "Ben", "occupation": "Horticulturalist" }
    ]
}