I have an Ember.js model with fixtures that looks like this:
App.Category = DS.Model.extend({
category: attr('string'),
friendly: attr('string'),
iconUrl: attr('string'),
isPrimary: attr('bool'),
isSecondary: attr('bool'),
isTertiaryOne: attr('bool'),
isTertiaryTwo: attr('bool')
});
App.Category.reopenClass({
FIXTURES: [
{
id: 1,
category: 'recommended',
friendly: 'recommended for you',
iconUrl: 'image1.png',
isPrimary: true,
isSecondary: false,
isTertiaryOne: false,
isTertiaryTwo: false
},
{
id: 2,
category: 'recent',
friendly: 'recently viewed',
iconUrl: 'image2.png',
isPrimary: false,
isSecondary: true,
isTertiaryOne: false,
isTertiaryTwo: false
}
]
});
All I want to do is retrieve a property value from a specific model, and set it to a new value in an action in my controller:
App.CategoryController = Ember.ArrayController.extend({
actions: {
tileClick: function (selectedCategory) {
var cat = this.store.find('category', { category: selectedCategory });
console.log(cat.get('isPrimary'));
cat.set('isPrimary', true);
}
}
});
The Emberjs website guides say that all I have to do to set a value is :
var tyrion = this.store.find('person', 1);
// ...after the record has loaded
tyrion.set('firstName', "Yollo");
but it just isn't working.
The variable 'cat' exists, and if I drill down deep enough into the object in the console, I can see the properties I want, so I know the correct model is being selected.
Aucun commentaire:
Enregistrer un commentaire