从数据库绑定 ExtJs 菜单



请提供一些示例代码或想法,如何从Json结果动态绑定菜单我从数据库中获取的结果为 json,那么如何从 json 绑定菜单(父级和子级)

提前致谢

其实很容易。当您从服务器返回数据时,您需要做的就是在 JSON 中包含定义记录结构的元数据字段。

请参阅此文档: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" }
    ]
}