findAll()中的deleteRecord和findQuery() [英] deleteRecord in findAll() vs findQuery()

查看:63
本文介绍了findAll()中的deleteRecord和findQuery()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚遇到以下问题:在ArrayController中的$ code>内容中调用 deleteRecord() findQuery(< model name> {})的路线中设置,该模型未从 ArrayController ,即使 deleteRecord 成功(并且我调用保存来持久化该操作)。但是,当我将其切换到 findAll()时,一切都按预期运行。任何想法可能是什么?

I just had the following problem: When calling deleteRecord() on a model in an ArrayController, whose content was set in the route with findQuery(<model name>, {}), the model was not removed from the ArrayController, even though deleteRecord was successful (and I called save to persist the action). However, when I switched it to findAll(), everything worked as expected. Any ideas why that might be?

我正在使用Ember 1.4.0-beta.1 + canary.4ffecd62和Ember Data 1.0.0-beta.4 + canary。 7af6fcb0。

I am using Ember 1.4.0-beta.1+canary.4ffecd62 and Ember Data 1.0.0-beta.4+canary.7af6fcb0.

推荐答案

find('type',{}) findQuery('type',{})创建一个RecordArray。 findAll('type') / find('type')实际返回一个现有的RecordArray,它具有所有当前的在商店记录。

find('type', {})/findQuery('type', {}) creates a RecordArray. findAll('type')/find('type') actually returns a live RecordArray which has all of the current records in the store.

为了更全面地了解这一点,商店里还有另外两种方法 all / 返回Live RecordArrays,但是它们不会调用服务器进行记录。您可以将 findAll('type') / find('type')作为调用服务器的方法然后调用全部方法。

To more fully understand this there are two other methods on the store all/filter which return Live RecordArrays, but they make no call to the server for records. You can think of findAll('type')/find('type') as a method of calling the server then calling the all method.

如果您希望可以根据 findQuery 来欺骗并获得类似的效果。

If you wanted you could create a filter based off the results of your findQuery to cheat and get a similar effect.

  model: function() {
    return this.get('store').find('color', {dummy:'data'});
  },
  setupController:function(controller, model){
    var filter = this.store.filter('color', function(color){
      return model.contains(color);
    }); 

    this._super(controller, filter);
  },

http://emberjs.jsbin.com/OxIDiVU/114/edit

这篇关于findAll()中的deleteRecord和findQuery()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆