避免同步模型的某些部分
假设我有一个像这样的 Sencha Touch 模型:
Ext.regModel('User', {
'fields': [{
'name': 'first_name',
'type': 'string'
}, {
'name': 'last_name',
'type': 'string'
}, {
'name': 'full_name',
'type': 'string',
'convert': function(v, record) {
return record.data.first_name + ' ' + record.data.last_name;
}
}, {
'name': 'age',
'type': 'integer'
}
]});
服务器在获取记录时返回“first_name”、“last_name”和“age”字段。但是,当我更新用户的名字和/或姓氏,并在商店上调用 sync()
时,它会将所有字段发送到服务器,包括全名和年龄,即使我不这样做我不想那样。
我知道我可以忽略服务器上的数据,但在某些情况下(例如,有很多带有“转换”的字段),它会给有效负载增加很多不必要的开销。
Let's say I have a Sencha Touch model like this:
Ext.regModel('User', {
'fields': [{
'name': 'first_name',
'type': 'string'
}, {
'name': 'last_name',
'type': 'string'
}, {
'name': 'full_name',
'type': 'string',
'convert': function(v, record) {
return record.data.first_name + ' ' + record.data.last_name;
}
}, {
'name': 'age',
'type': 'integer'
}
]});
The server returns the 'first_name', 'last_name', and 'age' fields when getting records. However, when I update a user's first and/or last name, and I call sync()
on the store, it will send all fields to the server, including full_name and age, even though I don't want that.
I know I could just ignore that data on the server, but in some cases (with lots of fields with 'convert' for example) it adds lots of unnecessary overhead to the payload.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过该字段的配置
persist: false
?编辑 我想您可以为代理创建自己的编写器并覆盖
getRecordData
方法。希望有帮助
Have you tried the config
persist: false
for the field?Edit I guess you could create your own writer for the proxy and override the
getRecordData
method.Hope it helps