ember-data's store的'defaultTransaction'
中的get(this, 'defaultTransaction').commit();
究竟是什么?
答案 0 :(得分:3)
取自源代码inline documentation:
此方法将保存委托给商店隐含 交易。调用此方法本质上是一个持久的请求 对未明确添加到的记录的任何更改 交易。
由于您可以创建新的交易来控制记录的持久性,因此想象一下 - defaultTransaction
就是这种情况。换句话说,每次都需要进行交易 - 你记录一些CRUD的时间,但如果你没有指定,那么就会使用商店的defaultTransaction
。
为了更清楚,请参阅从here获取的方法createRecord
:
createRecord: function(type, properties, transaction) {
properties = properties || {};
// Create a new instance of the model `type` and put it
// into the specified `transaction`. If no transaction is
// specified, the default transaction will be used.
var record = type._create({
store: this
});
transaction = transaction || get(this, 'defaultTransaction');
...
代码行transaction = transaction || get(this, 'defaultTransaction');
显示全部内容,如您所见,如果没有为刚创建的记录指定任何事务,则将使用defaultTransaction
。
希望它有所帮助。