選擇我定義我的選擇如下採用淘汰賽
<select id="selProductType" data-bind="options: productType , value: editProductType , optionsText: 'Name'" />
下面默認值是我的代碼,以填補選擇在我的視圖模型
// Loading combobox with Product Types
$.getJSON("../RestService/Product/AllProductTypes",
function (allData) {
var mappedProductType = $.map(allData, function (item) {
console.log(item.Id + ' ' + item.Name);
return new productType(item);
});
self.productType(mappedProductType);
});
當我初始化頁面,我想設置默認值來選擇。所以我想下面
self.editProductType(4);
但它給了我TypeErrror說對象4沒有方法Id。
如何去做。我也經歷了類似的帖子在stackoverflow,但沒有運氣。
Knockout JS binding initial/default value of dropdown (select) list
你有一個額外的「中選擇元素 – phnkha
是啊對不起,我刪除它 – DevelopmentIsMyPassion