将参数传递给save() [英] Passing parameters to save()
本文介绍了将参数传递给save()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以传递这样的参数?我需要传递一些不属于模型本身的信息。
Is it possible to pass parameters like this? I need to pass some information that is not part of the model itself.
myModel.save({site : 23})
推荐答案
如果可能的话:
- 为模型添加 volatile属性,
- 定义自定义模型序列化程序,并覆盖其
serializeIntoHash
方法。
- add a 'volatile' attribute to your model,
- define a custom model serializer, and override its
serializeIntoHash
method.
例如:
App.Model = DS.Model.extend({
//...
site: DS.attr('number', { serialize: false })
});
App.ModelSerializer = DS.RESTSerializer.extend({
serializeIntoHash: function(hash, type, record, options) {
this._super(hash, type, record, options);
Ember.merge(hash, {
'site': record.get('site')
});
}
});
请参阅此评论,这是实现目标的正确方法。
See this comment, this is the correct way to achieve your goal.
这篇关于将参数传递给save()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文