[英]Partial update in Ember-Data?
Imagine a bug tracker. 想象一下bug追踪器。
Each ticket contains a lot of data. 每张票都包含大量数据。 Now the status of a few tickets from a long list of tickets is updated.
现在,更新了一长串票证中的几张票的状态。
App.Ticket = DS.Model.extend({
id: DS.attr('number'),
status: DS.attr('string'),
...
});
Currently when invoking save
in ember-data this would send the complete models to the server. 目前,当调用ember-data中的
save
,这会将完整的模型发送到服务器。
What can I do to only send a partial update, like [{"id": 1, "status": "closed"}, {...}]
? 我该怎么办才能发送部分更新,例如
[{"id": 1, "status": "closed"}, {...}]
?
PS: I understand that this is not possible right now, so I'm wondering if there is a workaround / modification that would enable this? PS:我知道现在这是不可能的,所以我想知道是否有解决方法/修改可以实现这一点? (a general-purpose solution is not required).
(不需要通用解决方案)。
My current workaround is to specify a readOnly
option that excludes the attributes that I don't want to be sent in the POST. 我目前的解决方法是指定一个
readOnly
选项,该选项排除我不希望在POST中发送的属性。
Details can be found here: https://github.com/emberjs/data/pull/303#issuecomment-13993905 详情请见: https : //github.com/emberjs/data/pull/303#issuecomment-13993905
I was looking into this as well and if you want this to apply to all saves, then today you would fix it with a serializer like serializers/ticket.js
: 我也在研究这个问题,如果你想将它应用于所有保存,那么今天你可以用序列
serializers/ticket.js
这样的serializers/ticket.js
修复它:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
attrs: {
status: {serialize: false}
}
});
This would strip out status
. 这将剥夺
status
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.