And*_*aus 5 ember.js ember-data
因此,Ember数据模型具有在不将其提交到后端deleteRecord()的destroyRecord()情况下执行的功能。
我该怎么做save(),而不将其提交到后台?
我需要它的原因是,我正在使用自定义服务在一个请求中批量保存多个不同类型(模型)的记录。我已成功发送请求,并且记录保留在后端。
但是由于请求没有通过Ember Data管道,因此除非我手动处理,否则服务器的响应将被丢弃。
基本上,我在服务中有此功能:
// Accepts an array of records of mixed types,
// both existing and new
batchSave (records) {             
  this
    .customAjax(records)          // The records are persisted
    .then(payload => {            // Response from the backend with updated records
      store.pushPayload(payload); // Now all records have been updated with their current state
      // Now all the records are in their current state.
      // But they are still dirty!
      // How do I mark them clean and saved
    });
Run Code Online (Sandbox Code Playgroud)
我已经看到了这一点,但是它似乎丢弃了脏属性,而我希望脏属性变得干净。
我也尝试过,store.didSaveRecord()但是记录仍然很脏。
根据Ember Guides,使用store.createRecord()will 创建记录并将其添加到商店,但它不会向后端发出请求。
例子:
store.createRecord('post', {
  title: 'Rails is Omakase',
  body: 'Lorem ipsum'
});
Run Code Online (Sandbox Code Playgroud)
商店对象在控制器和路由中可用this.store。
然后如果你想坚持它,只需调用save().
例子:
post.save(); // => POST to '/posts'
Run Code Online (Sandbox Code Playgroud)
isDirty表示该记录具有适配器尚未保存的本地更改。这包括已创建(但尚未保存)或删除的记录。
脏状态有三个子状态:
uncommitted:商店尚未将要保存的记录移交。inFlight:商店已将要保存的记录移交,但适配器尚未确认成功。invalid:记录包含无效信息,尚无法发送到适配器。如果你想清理记录,请尝试这样的事情(未经我测试):
record.get('stateManager').send('becameClean'); 
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           2506 次  |  
        
|   最近记录:  |