ember.js - Ember data - computed property not firing when model is updated with createRecord -
for reasons beyond scope of question, have populate ember data model named activity in searchroute using ember.$.getjson in model hook this:
app.searchroute = ember.route.extend({ model: function (params) { // create promise return model hook. promise return ds.recordarray. var modelpromise = new ember.rsvp.promise(function (resolve, reject) { // make ajax call retrieve activities match search criteria ember.$.getjson('/services/activities?query=' + params.q).then(function (data) { data.activities.foreach(function (activity) { // if current activity not exist in store... if (!this.store.hasrecordforid('activity', activity.id)) { // add activity store this.store.createrecord('activity', { id: activity.id, title: activity.propertybag.title }); } }.bind(this)); resolve(this.store.all('activity', { query: params.q })); }.bind(this)); }.bind(this)); // return ds.recordarray model search route return modelpromise; } });
then, in searchcontroller model sorting , filtering before returning results computed property bound template displays results, this:
app.searchcontroller = ember.arraycontroller.extend({ filteredactivities: function () { var model = this.get('model'); // complete various model sorting , filtering operations return model; }.property('model') });
here's template:
<script type="text/x-handlebars" data-template-name="activities"> {{#each item in filteredactivities}} {{item.title}} {{/each}} </script>
every time search executed, model hook in searchroute refreshed, ajax request made, , store updated new activity records, if necessary.
the problem is, if create new records in store using createrecord , return new store query results model hook, filteredactivities property not fired , template not update.
i think because i'm returning newly updated ds.recordarray model hook, ember consider model having changed , fire computed properties watching changes model, must missing something.
does have ideas?
sorry long post, , thank taking time consider issue!
don't use createrecord
. use push
.
http://guides.emberjs.com/v1.10.0/models/pushing-records-into-the-store/
Comments
Post a Comment