JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ember.js – model.save()与model.get(‘store’)的区别.commit()大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
有什么区别?
// 'this' is the controller
this.get('model').save();

// 'this' is the controller
this.get('model').get('store').commit();

?在我做的小测试中,他们都给了我相同的结果.@R_317_10675@用哪一个?

我调查了第一个,并呼叫

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())

解决方法

我建议使用this.get(‘model’).save()

如果您在同一个运行循环中保存多个记录,则scheduleSave将批量更改,以便多个记录将保存在同一个事务中.在某些情况下,提交可能会导致其他记录的更改被持久化.

大佬总结

以上是大佬教程为你收集整理的ember.js – model.save()与model.get(‘store’)的区别.commit()全部内容,希望文章能够帮你解决ember.js – model.save()与model.get(‘store’)的区别.commit()所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。