Google News
logo
Ember.js - Interview Questions
How to Finding Records in Ember.js?
The Ember Data store provides an interface for retrieving records of a single type.
 
Retrieving a Single Record : Use store.findRecord() to retrieve a record by its type and ID. This will return a promise that fulfills with the requested record:
// GET /blog-posts/1
this.store.findRecord('blog-post', 1)  // => GET /blog-posts/1
  .then(function(blogPost) {
      // Do something with `blogPost`
  });
Use store.peekRecord() to retrieve a record by its type and ID, without making a network request. This will return the record only if it is already present in the store:
let blogPost = this.store.peekRecord('blog-post', 1); // => no network request
Retrieving Multiple Records : Use store.findAll() to retrieve all of the records for a given type:
// GET /blog-posts
this.store.findAll('blog-post') // => GET /blog-posts
  .then(function(blogPosts) {
    // Do something with `blogPosts`
  });
Use store.peekAll() to retrieve all of the records for a given type that are already loaded into the store, without making a network request:
let blogPosts = this.store.peekAll('blog-post'); // => no network request
store.findAll() returns a PromiseArray that fulfills to a RecordArray and store.peekAll directly returns a RecordArray.
Advertisement