0
我有一個燈具模型Ember.js看起來像這樣:Ember.js - 無法獲取或設置模型屬性
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
}
]
});
所有我想要做的就是從一個特定的模式檢索屬性值,並將其設置爲一個新值的動作在我的控制器:
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);
}
}
});
的Emberjs網站導遊說,所有我必須做的設定值爲:
var tyrion = this.store.find('person', 1);
// ...after the record has loaded
tyrion.set('firstName', "Yollo");
但它只是不工作。
變量'cat'存在,並且如果我向控制檯中的對象深入鑽取足夠深,可以看到我想要的屬性,所以我知道正在選擇正確的模型。
完美,非常感謝! – benihana21 2015-02-06 21:10:02