我想在knockout中绑定select标签的选项值,值 从ko viewmodel传入,输入参数依赖于 外循环。
它确实显示了populate droupdownlist
就像这个伪代码
<-- ko for-each {data: travellerlist} -->
<select data-bind =" foreach: GetYearList($data.passengerType())" >
<option data-bind="value: key, text: value"></option> <select>
<--/ko-->
function GetYear(passengerType) {
$.ajax({
url: baseUrl + 'JavascriptVariables/YearList',
type: 'get',
data: { passengerType: passengerType },
success: function (data) {
var yearList = [];
if (data != null ) {
$.each(data, function (key, value) {
yearList.push(key, value);
});
debugger
return yearList;
}
},
error: function (data) {
}
}); }