0

so i have quota model like this :

 export default DS.model.extend({
 quota : DS.attr('number'),
 sellerId: DS.attr('string'),
 buyerId:DS.attr('string') });

and i have assignQuota routes with dynamic segment like this:

 this.route('assignQuota', {path:'/assignQuota/:buyer_id'}

and in assignQuota.js :

    export default Ember.Route.extend({
    model(params) {
    const sellerId = this.get("session").get("uid");
    return this.store.query('quota',{
    orderBy:'buyerId',
    equalTo: params.buyer_id
     }).then(function(quota){
      return quota.filterBy('sellerId',sellerId)    
     }); 
     }
     });

and in my template (simplify) is like this:

      {{#each model as |quota|}}
            {{quota.quota}}

          {{/each}}

it worked but if someone add data or delete data in quota model, the list didn't update automatically in the template.

The template only refresh after i refresh the browser. The funny thing is if I use ember inspector to inspect the data for quota, it shown that the model already changes if someone changes the model but the template didn't reflect the changes.

please help

thanks

marendra
  • 51
  • 1
  • 7

2 Answers2

2

The issue lies, how are you doing transitionTo to assignQuota route, If you are passing model to the dynamic segment,then it will skip calling the model hook and it will render same model data.

Ember Freak
  • 12,918
  • 4
  • 24
  • 54
  • this is what im using for : this.transitionToRoute("seller.assignQuota",params.user_id); – marendra Feb 22 '17 at 13:03
  • 1
    @user3720044 `store.query` is not live array, which means it will not be updated automatically when there is change in store. when you do transition through `transitionToRoute` method just ensure `model` hook should be called. if its called then you will definitely get fresh data. – Ember Freak Feb 22 '17 at 13:13
  • `it shown that the model already changes if someone changes the model but the template didn't reflect the changes` -> so it will be automatically updated in template only when you use `findAll` or `peekAll` since both returns live array – Ember Freak Feb 22 '17 at 13:16
0

The reason is that the model does not observe changes.

Create a computed property and make it observer change changes of the model, and then using the computed value to create a list (your each loop).

quotaList: Ember.computed('model.[]', function() {
    // Your update logic here
    // return the new value
})
locks
  • 6,537
  • 32
  • 39
XY L
  • 25,431
  • 14
  • 84
  • 143