New to ember and this is super dumb but I've wasted my day on it.
I'm creating an array of objects in my controller which i'm using to building radio buttons in my view.
when the button is clicked, i want to toggle the clicked attribute on the radio input so that it will appear clicked. Very simple but Ember keeps throwing me errors.
here's my code (edited some typos):
IndexController = Ember.ObjectController.extend({
radioArray : function () {
var a = [], i = 0;
while (a.push({ index: i++, clicked: false }), i <= 10);
return a;
}.property('radioArray'),
actions : {
assignClick : function (item, index) {
this.toggleProperty(item.clicked);
// some unrelated business logic here
}
}
});
this hooks up to:
{{#each radioArray}}
<label {{action "assignClick" this index}}>
<input type="radio" {{bind-attr value=index checked=clicked}} /> foo
</label>
{{/each}}
All i want is to show that the correct radio button has been clicked. But when i try and set clicked to true in my ctrl, i get "Uncaught Error: Assertion Failed: Cannot call get with false key."
toggleProperty
do? It seems like you’re missing a concept here;radioArray
is mapping directly to a set of objects, but those objects aren’t connected to anything. – Buck Doyle