DS.Store#filter()

filter (modelName, query, filter) DS.PromiseArraydeprecatedprivate

Defined in addon/-private/system/store.js:1550

Takes a type and filter function, and returns a live RecordArray that remains up to date as new records are loaded into the store or created locally.

The filter function takes a materialized record, and returns true if the record should be included in the filter and false if it should not.

Example

store.filter('post', function(post) {
  return post.get('unread');
});

The filter function is called once on all records for the type when it is created, and then once on each newly loaded or created record.

If any of a record's properties change, or if it changes state, the filter function will be invoked again to determine whether it should still be in the array.

Optionally you can pass a query, which is the equivalent of calling query with that same query, to fetch additional records from the server. The results returned by the server could then appear in the filter if they match the filter function.

The query itself is not used to filter records, it's only sent to your server for you to be able to do server-side filtering. The filter function will be applied on the returned results regardless.

Example

store.filter('post', { unread: true }, function(post) {
  return post.get('unread');
}).then(function(unreadPosts) {
  unreadPosts.get('length'); // 5
  var unreadPost = unreadPosts.objectAt(0);
  unreadPost.set('unread', false);
  unreadPosts.get('length'); // 4
});

Parameters:

modelName String
query Object
optional query
filter Function

Returns:

DS.PromiseArray
doc_EmberJs
2016-11-30 16:50:48
Comments
Leave a Comment

Please login to continue.