如何在store.sync()之后更新所有属性?

时间:2012-05-17 14:43:49

标签: extjs extjs4.1

同步()更新只有一行被更改但不是全部来自响应。

型号:

Ext.define('Exp.model.ProfileChannel', {
    extend: 'Ext.data.Model',
    fields: ['id', 'channel', 'server', 'profile'],

    proxy: {
        type: 'ajax',
        api: {
            read: '/profilechannel/list',
            update: '/profilechannel/save'
        },
        reader: {
            type: 'json',
            root: 'data'
        }
    }
});

商店:

Ext.define('Exp.store.ProfileChannels', {
    extend: 'Ext.data.Store',
    model: 'Exp.model.ProfileChannel',
    autoSync: true
});

让我们在店里说我有这样的记录:

{
    id: '1',
    profile: 'profile id',
    channel: '',
    server: ''
}

然后:record.set('channel', 'channel id');

响应

{
    "success":true,
    "data":[
        {
            id: '1',
            profile: 'profile id',
            channel: 'channel id',
            server: 'server id added on backend'
        }
    ]
}

最后,我有记录,就像这样:

{
    id: '1',
    profile: 'profile id',
    channel: 'channel id',
    server: ''
}

所以问题是如何更新和服务器值我在响应中有新值..这是一个错误吗?或者我做错了?如果extjs忽略它们,我为什么要把所有属性都放进去?

2 个答案:

答案 0 :(得分:2)

它应该完全符合您的预期。更新过程后从商店返回的所有记录都应替换您可能已在商店中拥有的本地副本。您可能想要检查ExtJs代码并对其进行调试以查看错误。

我绝对使用与ExtJs 4.0.7相同的逻辑。它可能会被破坏4.1,或者您可能需要调整商店/代理中的某些配置。

答案 1 :(得分:0)

我也有一些问题,记录没有在4.1上更新。经过一些调试后,我发现所有extjs模型字段需要在服务器响应中返回

extjs没有抛出任何错误,只有store.sync()和record.save()上的失败回调给我一个错误。很难找到......

相关问题