1
我在將新值插入數組時遇到未定義的錯誤。Knockout observablearray thows未定義錯誤
HTML:
<select id="temp" data-bind="options:Original"></select>
<select data-bind="options:dynamicaarry"></select>
視圖模型:
var ViewModal=function(items) {
this.dynamicaarry=ko.observableArray(items);
this.Original=ko.observableArray(['volvo','saab','mercedes','audi']);
};
ko.applyBindings(new ViewModal(['four']));
$("#temp").change(function() {
this.ViewModal.dynamicaarry.push('six'); //throws undefined error});});
}
,並有可能處理在淘汰賽selectedindexchange事件,而不使用jQuery?
您需要了解JavaScript中的「這個」關鍵詞:http://unschooled.org/2012/03/understanding-javascript-this/ –
的聯繫是非常豐富的。感謝budy – Dhinesh