【问题标题】:Not being able to map model in JsonStore using JsonReader in Sencha Touch无法在 Sencha Touch 中使用 JsonReader 在 JsonStore 中映射模型
【发布时间】:2011-12-01 02:49:14
【问题描述】:

我在使用 Ext.data.JsonReader 映射 Ext.data.JsonStore 模型时遇到问题。

来自服务器的 JSON 响应(服务器模型):

{"rows":[{"id":1,"firstname":"Bill"},{"id": 2,"firstname":"Ben"}]}

Json Store 中使用的模型:

Ext.regModel( 'mycabinet', {
fields: [ 
{ name : 'DeviceId', type: 'int' },
'CabinetName']
});

json阅读器代码:

var iccDeviceReader = new Ext.data.JsonReader({
// metadata configuration options:
idProperty: 'id',
root: 'rows',
fields: [
{name: 'CabinetName', mapping: 'firstname'},
{name:'DeviceId',mapping:'id'}
]
});

json 存储代码:

app.iccDS = new Ext.data.JsonStore( {
model : 'mycabinet',
sorters  : 'CabinetName',
getGroupString : function(record) { return record.get('CabinetName')[0]; },
proxy    : {
type: 'ajax',
url : '/icc/js/data.js',
reader:iccDeviceReader
},
autoLoad: true
} );

我预计“mycabinet”模型将填充“服务器模型”。但是,映射不会发生。 我什至尝试使用 convert 没有任何成功(name:'DeviceId',mapping:'id',convert: function(v){return v.id;})

我们将不胜感激任何帮助。 谢谢

【问题讨论】:

    标签: mapping sencha-touch jsonstore jsonreader


    【解决方案1】:

    以下代码解决了我的问题...

    Ext.regModel( 'mycabinet', {
    fields: [ 
    { name : 'DeviceId', type: 'int',mapping:'id' },
    {name: 'CabinetName', mapping: 'firstname'}]
    });
    
    app.iccDS = new Ext.data.JsonStore( {
    model : 'mycabinet',
    sorters  : 'CabinetName',
    getGroupString : function(record) { return record.get('CabinetName')[0]; },
    proxy    : {
    type: 'ajax',
    url : '/icc/js/data.js'
    },
    autoLoad: true
    } );
    

    我不再使用 jsonReader。

    【讨论】:

      【解决方案2】:

      从阅读器中删除“字段”选项,并在模型配置中将 'CabinetName' 更改为 {name: 'CabinetName', mapping: 'firstname'}。 此外,idProperty 也应该进入您的模型配置。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-10-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-21
        • 1970-01-01
        • 2011-03-01
        • 1970-01-01
        相关资源
        最近更新 更多