我想更新我保存在工厂中的全局数组中的一些值。
我使用 get 方法来获取数据,但 set 函数不知何故无法完成其工作,并且数组中的值不会更新。我缺少什么?
.factory('messageList', function () {
var Messages =
[
{ "title":"Cash in", "icon":"ion-social-euro",
"dailyValue": "0", "weeklyValue": "0", "monthlyValue": "0",
"category": "financial", "active": "true"
},
{ "title":"Sales orders", "icon":"ion-social-euro",
"dailyValue": "0", "weeklyValue": "0", "monthlyValue": "0",
"category": "sales", "active": "true"
}
]
return {
get: function() {
return Messages;
},
set: function(title, key, newValue) {
for (var i = 0; i < Messages.length; i++) {
if(Messages[i].title == title){
Messages[i].key = newValue;
}
}
}
}
})
这就是我尝试更新控制器中的值的方法:
messageList.set("Sales orders","dailyValue", $Scope.sum);