0

I have an ArrayContoller on which I want to set a boolean property based on the properties of its contents.

Plain-language description of the logic:

If the array contains any items with a property of isRetired equal to true, set the retiredShoes property of the ArrayController to true, otherwise, set the ArrayController retiredShoes property to false.

It seems like this should be a simple matter, but I haven't found a solution anywhere, and I'm still pretty new at this.

I'll put together a jsfiddle if necessary.

Here are the controllers for the array and the object:

App.ApplicationController = Ember.ArrayController.extend({
    sortProperties: ['title'],
    itemController: 'shoe',
    retiredShoes: function() {
        //how do I compute this sucker?
    }
});

App.ShoeController = Ember.ObjectController.extend({
    needs: ['application'],
    actions: {
        delete: function() {
            var shoe = this.get('model'),
                runs = shoe.get('runs');
            shoe.deleteRecord();
            shoe.save();
        },
        toggleRetired: function() {
            var shoe = this.get('model');
            shoe.toggleProperty('isRetired');
            shoe.save();
        }
    }
});

1 Answer 1

2

Off top of my head, without jsbin. If there's a problem/bug, drop me a comment and I'll look it over again.

App.ApplicationController = Ember.ArrayController.extend({
    retiredShoes: function() {
        return this.get("model").isAny("isRetired", true);
    }.property("[email protected]")
});
Sign up to request clarification or add additional context in comments.

1 Comment

The top of your head was exactly right. I KNEW it had to be simple. Many thanks, @panta82.

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.