Eri*_*son 1 ember.js ember-data
我有一个比赛模型,其中包含与之相关的一系列比赛.假设我想立刻销毁集合中的所有匹配项,应该怎么做?这是我尝试过的:
var matches = tournament.get('matches').toArray();
for (var i = 0; i < matches.length; i++) {
  matches[i].destroyRecord();
}
tournament.save().then(function(tournament) {
  that.transitionTo('tournaments.setup', tournament); 
});
这个toArray位似乎不正确,但它会阻止修改迭代,因为我遍历它.似乎应该有一种方法可以立即销毁所有这些比赛,然后保存比赛.
小智 6
这是完成这项工作的一点点技巧
tournament.get('matches').invoke("destroyRecord"); // deletes all records in 1 shot
如果您希望将其用作承诺
Ember.RSVP.all(tournament.get('matches').invoke("destroyRecord"))
   .then(function(){
         tournament.save()
          .then(function(tournament) {
            that.transitionTo('tournaments.setup', tournament); 
          });
});
| 归档时间: | 
 | 
| 查看次数: | 906 次 | 
| 最近记录: |