有什么区别?
// 'this' is the controller this.get('model').save();
和
// 'this' is the controller this.get('model').get('store').commit();
?在我做的小测试中,他们都给了我相同的结果.我应该使用哪一个?
我调查了第一个,并呼叫
DS.Model = Ember.Object.extend( ... save: function() { this.get('store').scheduleSave(this); var promise = new Ember.RSVP.Promise(); this.one('didCommit',this,function() { promise.resolve(this); }); return promise; },
那么问题就变成了,这个.get(‘store’).scheduleSave(this)和this.get(‘store’)之间的主要区别是什么?commit()?
DS.Store = Ember.Object.extend(DS._Mappable,{ ... scheduleSave: function(record) { get(this,'currentTransaction').add(record); once(this,'flushSavedRecords'); },... /** This method delegates committing to the store's implicit transaction. Calling this method is essentially a request to persist any changes to records that were not explicitly added to a transaction. */ commit: function() { get(this,'defaultTransaction').commit(); },
我不知道哪一个更好.我正在倾向于保存(),因为它似乎在商店周围.
(我在github上找不到这些代码,不知道github或者emberjs的amazonaws版本是否是最新版本,这是github上的类似版本:model’s save(),它调用store’s scheduleSave()和store’s commit())
解决方法
Which one should I use?
我建议使用this.get(‘model’).save()
what’s the main difference between
this.get('store').scheduleSave(this)
andthis.get('store').commit()
?
如果您在同一个运行循环中保存多个记录,则scheduleSave将批量更改,以便多个记录将保存在同一个事务中.在某些情况下,提交可能会导致其他记录的更改被持久化.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。