Divya
Divya

Reputation: 377

Ember computed property on a DS model record is not firing when the record is changed

Ex:

I have model/test.js

export default Model.extend({
  name: attr('string'),
  email: attr('string'),
  address: attr('string'),
  age: attr(),
  phone: attr()
});

In component.js

list: computed('model.{}', function() { });

Fetching data in route and passing it to the template. In child component i am trying to access it. initially data passed will be like

{
  'data': {
    name: 'test'
  }
}

later sending data as

{
  'data': {
    name: 'test',
    email: '[email protected]',
    address: 'XYZ',
    age: 10,
    phone: 423423
  }
}

But in computed property it is not listening second updated data. I want to listen dynamically each property in model. It will work if i give like

list: computed('model.{name,email,address,age,phone}', function() { });

But i want some other solution for it. Dynamically need to listen each property in model object.

Upvotes: 1

Views: 247

Answers (2)

Ember Freak
Ember Freak

Reputation: 12872

If you are dealing single object, then what you have is the right and only possible way to go.

list: computed('model.{name,email,address,age,phone}', function() { });

Suppose if your model is array of object then you can do the below things,

list: computed('model.@each.{name,email,address,age,phone}', function() { });

Upvotes: 0

Mohanesh
Mohanesh

Reputation: 24

You can try using @each in the computed property.

list: computed('model.@each', function(){});

It will work for all properties inside the model class. But it works only one level deep.

Upvotes: 0

Related Questions