jeudi 2 juillet 2015

Ember computed property for object attribute

My component receives an object property named "line" and a string property named "name".

{{field-row line=model name=fieldName}}

The line object has several attributes. The following Ember computed property "value" returns the value based on the given line and name:

value: Ember.computed('line', function() {
    const line = this.get('line');
    const name = this.get('name');
    return line.get(name);
})

This works, but any updates to the line object's attribute won't automatically trigger a refresh on the component's template. I guess that's because the reference to the 'line' object remains the same while its attribute content changes. Since the name of the attribute can not be known beforehand, I tried this but it doesn't work either:

value: Ember.computed('line.@each', function() {
    const line = this.get('line');
    const name = this.get('name');
    return line.get(name);
})

Any ideas?




Aucun commentaire:

Enregistrer un commentaire