我正在尝试编写一个函数,该函数 1. 将一个项目添加到可观察数组中,2. 如果该项目已存在于数组中,则替换该项目
self.addNotification = function (name, availability, note) {
//see if we already have a line for this product
var matchingItem = self.notifications.indexOf(name);
if (matchingItem !== undefined) {
self.notifications.replace(self.notifications()[index(matchingItem)],
new Notification(self, name, availability, note));
}
else {
self.notifications.push(new Notification(self, name, availability, note));
}
};
我究竟做错了什么?
问候安德斯