Javascript findQuery()在余烬数据中不起作用?

Javascript findQuery()在余烬数据中不起作用?,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,夹具包含触点列表,每个触点都有触点类型。 我正在尝试使用.findQuery()筛选联系人记录,但它引发以下错误: Uncaught TypeError: Object function () {.....} has no method 'findQuery' 我在这里列出了我的代码: Grid.Store = DS.Store.extend({ revision: 12, adapter: 'DS.FixtureAda

夹具包含触点列表,每个触点都有触点类型。 我正在尝试使用.findQuery()筛选联系人记录,但它引发以下错误:

Uncaught TypeError: Object function () {.....} has no method 'findQuery' 
我在这里列出了我的代码:

Grid.Store = DS.Store.extend({
                  revision: 12,
                  adapter: 'DS.FixtureAdapter'
            }); 

    Grid.ModalModel =  DS.Model.extend({
    fname: DS.attr('string'),
    lname: DS.attr('string'),
    email: DS.attr('string'),
    contactno: DS.attr('string'),
    gendertype: DS.attr('boolean'),
    contactype: DS.attr('number')
});

Grid.ModalModel.FIXTURES = [
                       {
                         id: 1,
                         fname: "sachin",
                         lname: "gh",
                         email: "gh",
                         contactno: "4542154",
                         gendertype: true,
                         contactype: 1
                       },
                       {
                         id: 2,
                         fname: "amit",
                         lname: "gh",
                         email: "gh",
                         contactno: "4542154",
                         gendertype: true,
                         contactype: 2
                       },
                       {
                         id: 3,
                         fname: "namit",
                         lname: "gh",
                         email: "gh",
                         contactno: "4542154",
                         gendertype: true,
                         contactype: 1
                       }
                      ];
控制器代码:

        totpersonalcontact:function(){ 
        return Grid.ModalModel.findQuery({ contactype: 2 }).get('length'); 
    }.property('@each.isLoaded'),
    totfriendcontact:function(){ 
        return Grid.ModalModel.findQuery({ contactype: 3 }).get('length'); 
    }.property('@each.isLoaded')

我已将.findQuery更改为.query,但每次它都将长度显示为0。

只需将
findQuery
更改为
query

在此之后,控制台中将显示一条错误消息:

Assertion failed: Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store. 
就像消息解释一样,只需实现
DS.FixtureAdapter#queryFixtures
。 传递给
queryFixtures
的参数是:记录、查询、类型。其中:

  • 记录
    是一个普通javascript对象数组,您将对其进行筛选
  • Query
    是传递给ember数据类的
    Query
    方法的对象
  • Type
    是余烬数据类,查询在其中调用
返回的是经过过滤的数据

例如,要执行简单的where like:

App.Person.query({ firstName: 'Tom' })
只需使用以下命令重新打开您的
DS.FixtureAdapter

DS.FixtureAdapter.reopen({
    queryFixtures: function(records, query, type) {        
        return records.filter(function(record) {
            for(var key in query) {
                if (!query.hasOwnProperty(key)) { continue; }
                var value = query[key];
                if (record[key] !== value) { return false; }
            }
            return true;
        });
    }
});

是一个现场演示。

我正要发布一个答案,但你的答案补充得非常好,所以请投票给你:)谢谢@inuitivepixel!由于一些教程中缺少ember数据,有时我会花一些时间提供有关该问题的其他信息,当我有时间:)谢谢,@Márciordriguescorreajúnior它现在可以工作了,但每次我的长度都是0。美学上,哲学上,在ember中没有默认设置的原因是什么?@ahnbizcad请查看此线程。