我用下面的代碼獲得knockoutJs選定值
<select data-bind="options: preferedTimeToPickup,optionsCaption: 'Choose...',
optionsText: 'name',value: preferedTimeToPickupVal" id="u3413_input" class="text_sketch">
</select>
在KnockoutJs
this.preferedTimeToPickup =
[{name:"Specific: 8:00",price:10.25},
{name:"Specific:9:00",price:12.25 },
{name:"Specific: 10:00",price:13.25}
];
this.preferedTimeToPickupVal = ko.observable();
當我試圖讓價格選擇使用下面的代碼選擇同時傳遞值select data
。
this.subtotal = ko.computed(function() {
return this.preferedTimeToPickupVal().price;
});
我得到以下錯誤
Uncaught TypeError: Cannot read property 'preferedTimeToPickupVal' of undefined
任何一個可以請幫我在這。
我是新來的knockoutJs,我不明白這個錯誤。請解釋。 –