0
在我的視圖模型中,我有一些方法可以重置可觀察數組中的數據。當我第一次點擊一個叫做newGame
方法的按鈕時,一切正常。但是,第二次點擊按鈕我得到一個JavaScript錯誤。Knockout JS removeAll()第二次調用
self.newGame = function() {
// reset the zones
self.resetBoardState();
// more stuff here but clipped for brevity ...
}
self.resetBoardState = function() {
// clear all zones...
self.library.removeAll();
// place all cards in deck into library ...
self.library = JSON.parse(JSON.stringify(self.deck));
}
我得到在JavaScript控制檯中的錯誤是:
Uncaught TypeError: Object [object Array] has no method 'removeAll'
我有一個JS Fiddle這裏,所以整體視圖模型可以看出。如果您第一次點擊「新遊戲」按鈕,一切正常。您也可以點擊「繪製卡片」按鈕,它的行爲也是正確的。然而,點擊「Mulligan」按鈕會再次點擊「New Game」會導致相同的錯誤。
我能做些什麼來獲得這個功能?
謝謝。現在看來很明顯,你指出了它。 –