0

Here's the component:

export default Ember.Component.extend({
    columns: []

    _watchColumns: function () {
        // console.log(changedValue);
    }.observes('[email protected]')

    // other code
});

I'd like to get the changed value in _watchColumns method. Is it possible?

4
  • Maybe _watchColums: function(newVal) will return the new value? It's like this in Angular, no idea with Ember. Commented Jul 4, 2015 at 10:39
  • Yes, that would be the desired behavior for me, but it doesn't work like that. Commented Jul 4, 2015 at 10:41
  • Tried reading the docs but it doesn't really explain anything about it strangely enough. Commented Jul 4, 2015 at 10:42
  • Perhaps this will help you in some way: guides.emberjs.com/v1.10.0/object-model/observers Commented Jul 4, 2015 at 10:43

1 Answer 1

1

I don't think this is possible. A workaround might be to use a component for each item.

My-Columns component

//my-columns.js
export default Ember.Component.extend({
    columns: null
});

//my-columns.hbs
{{#each columns as |column|}}
    {{my-column value=column}}
{{/each}}

My-Column component

//my-column.js
export default Ember.Component.extend({
    nameUpdated : Ember.computed('value.name', function() {
        console.log(this.get('value.name'));
    });
});

Another tip: never set a property to [] or {} in a component as it will be shared across all instances of the compoent (like a static property - unless you want this behaviour of course). In your case the user will override it by passing in their own columns object but it is helpful to know anyway. If you need an array in your component you can do this:

export default Ember.Component.extend({
    myArray : null,
    init : function() {
        this._super.apply(this, arguments);
        this.set('myArray', []);
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Vote up for the tip :).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.