ember.js - Filter a list of objects using computed properties? -


short context - using ember , ember-data present list of events user. events aggregated in api endpoint, , each has "kind" property notes type event (announcement, etc). events filtered @ api level user (so have query on user_id user's list of events.

i need display these events on single page, break them kind. there's fixed list of kinds, can call them , b.

my intuition set model in eventsroute so:

model: function () {  return this.store.find('events', {user_id: $.cookie('user_id')}); } 

and make various event types filters on eventscontroller:

announcements: function() {   return this.get('model').filterby('kind', 'announcement'); }.property(), 

this works, @ least in test cases. i'm not sure it's right way go things, though. haven't quite grokked difference between properties (which seem set on controller) , model (which route sets). so, questions are:

  1. is right way go creating filtered sublists of data? should not rely on .get('model') call pull underlying data?
  2. should property() call name anything? these should recomputed when underlying model changes, far can tell, ember quiet when pass in garbage property() call ({}.property('potato') doesn't fail), don't know if .property('model') or .property('@each') appropriate here.

is right way go creating filtered sublists of data? should not rely on .get('model') call pull underlying data?

yes right way it. since arraycontroller can use .get('model') or .get('content') access array.

should property() call name anything?

yes should list dependencies cause property recomputed. sure ember quiet if don't exist. in case should use .property('model.@each.kind')


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -