我有一個元素加載到我的項目中的問題Observable-Array - 帶有事件。Knockout.js:將元素添加到observable-array
ViewModel = (function() {
var
items = ko.observableArray([]),
removeItems = function (element) {
items.remove(element);
},
saveAll = function() {
return ko.toJS(items);
},
addItem = function (element) {
items.push(element);
return false; // no Page-Reload after button-klick
};
return {
Items: items,
// i call addItem with a dummy object (for testing)
clickSave: addItem(new Customer(1, "Tfsd", "Tfsd"))
};
})();
(fiddle)
爲什麼叫的addItem功能,甚至不需要點擊按鈕?是因爲函數末尾的()嗎?
addItem = function (element) {
items.push(element);
return false; // no Page-Reload after button-click
};
我該怎麼做才能讓這個事件發生? 或者是我的問題在別的地方?