FindQuery () not working in ember data?

The luminaire contains a list of contacts, and each contact has a type of contact. I am trying to filter contact entries using .findQuery (), but it throws the following error:

Uncaught TypeError: Object function () {.....} has no method 'findQuery' 

I have listed my code here:

 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 } ]; 

Controller Code:

  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') 

I changed .findQuery to .query, but every time it shows the length as 0.

+4
source share
1 answer

Just change findQuery to query .

After that, an error message will appear in the console:

 Assertion failed: Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store. 

Like the explanation of the message, just do DS.FixtureAdapter#queryFixtures . The parameters passed to queryFixtures are: records, query, type. Where:

  • Records is an array of simple javascript objects that you will filter.
  • query is an object passed to the query method of your ember data class.
  • Type is the ember data class where the request is a call.

And the return is the filtered data.

For example, to do simple, for example:

 App.Person.query({ firstName: 'Tom' }) 

Just open the DS.FixtureAdapter with:

 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; }); } }); 

Here is a live demonstration.

+17
source

Source: https://habr.com/ru/post/1496347/


All Articles