モデルで ArrayProxy を使用している場合、その配列内の特定の要素のプロパティを更新する方法が見つかりません。
サンプルのルートとコントローラーは次のとおりです。
App.IndexRoute = Ember.Route.extend({
model: function() {
return Ember.ArrayProxy.create({
content : [
{ firstName : "Bob", lastName : "Smith" },
{ firstName : "George", lastName : "Jhnsn"}
]
});
}
});
App.IndexController = Ember.Controller.extend({
actions : {
fixGeorgesLastName : function(){
// how to I change the last name to 'Johnson' ???
console.log(this.get("model").objectAt(1).lastName); // Jhnsn
var georgeObjFromModel = this.get("model").objectAt(1);
console.log(georgeObjFromModel.lastName); // Jhnsn
// georgeObjFromModel.objectAt(1).lastName = "Johnson"; // error !!! TypeError: Object #<Object> has no method 'objectAt'
}
}
});
lastName
2 番目の要素の値を変更するにはどうすればよいですか?
同じ配列のローカル バージョンでそれを行う方法を理解できます。
// local instance of same array
var localCustomerArray = Ember.ArrayProxy.create({
content : [
{ firstName : "Bob", lastName : "Smith" },
{ firstName : "George", lastName : "Jhnsn"}
]
});
// works fine
console.log("before: " + localCustomerArray.objectAt(1).lastName); // Jhnsn
localCustomerArray.objectAt(1).lastName = "Johnson";
console.log("after: " + localCustomerArray.objectAt(1).lastName); // Johnson
私が間違っていることは何か分かりますか?