0
我試圖使用映射插件,使兒童對象的屬性可觀察。我有以下幾點:對象未定義與Knockout數據映射插件
// setData defined here
var mapping = {
create: function(options) {
//customize at the root level.
var innerModel = ko.mapping.fromJS(options.data);
innerModel.cardCount = ko.computed(function() {
debugger;
return this.cards().length; // cards not defined - "this" is Window for some reason
});
innerModel.deleteCard = function (card) {
// Pending UI
// call API here
// On success, complete
this.cards.remove(card);
}.bind(this);
innerModel.addCard = function() {
//debugger;
// Pending UI
// Call API here
// On success, complete
this.cards.push(dummyCard);
//this.cardToAdd("");
}.bind(this);
return innerModel;
}
};
var SetViewModel = ko.mapping.fromJS(setData, mapping);
ko.applyBindings(SetViewModel);
當我在Chrome調試器中運行,我得到「對象[對象全局]有沒有方法卡」。卡應是一個可觀察的數組。我究竟做錯了什麼?
感謝本,幫助很大。 – JakeP 2013-03-24 03:49:55