存储多层次

时间:2011-09-09 09:00:36

标签: extjs4

我有以下json:

{"service":
{"description":"Export a list of amendments.","id":"504e1bf57e8d2fdd92b6c316cd000b25","name":"AT4AM_AmendmentsList","notes":"Export a list of amendments in a defined format, Word or XML.\r\n\r\n\"keywords\" : [ \"AT4AM\", \"DST\", \"Amendment\", \"Export\", \"Word\", \"XML\" ]","revision":"2-cd375cfd296ba97e934f12794d4930e9","status":"study","type":"entity",
"versions":[{"description":"v1.0 description...","id":"504e1bf57e8d2fdd92b6c316cd0017c0","version":1}]}}

我想将版本列表显示在网格中。

这是我的模特:

Ext.define('XXXX.model.Version', {
extend: 'Ext.data.Model',
fields : [ {
    name : 'id',
    type : 'string'
}, {
    name : 'description',
    type : 'string'
}, {
    name : 'version',
    type : 'string'
}],
belongsTo: 'XXXX.model.Service',
proxy: {
    type: 'rest',
    id: 'id',
    url : 'http://localhost:8080/xxxxx/services/service',
    reader: {
        type: 'json',
        root: 'versions'
    }
}       

});

感谢您的帮助 混合

2 个答案:

答案 0 :(得分:0)

在读者的配置中使用root: 'service.versions'

答案 1 :(得分:0)

以下是我找到的解决方案:

1 - 我将此添加到模型“服务”

{type: 'hasMany', model: 'XXXX.model.Version', name: 'versions'}

2 - 我使用配置的RestProxy发出GET请求

Ext.ModelManager.getModel('XXXX.model.Service').load(serviceId, {
            success: function(service) {
            // Now, it is possible to access to all the versions of a service
            service.versions().each(function(version) {
                    listOfVersions.push(version.data);
    });

}
});

此致 混合