我有一个名为的方法,它返回一个List<string>。第一个返回年份列表,并使用jQuery填充select:
$.ajax({
url: $yearDropDownList.attr('data-request-url'),
method: 'GET',
dataType: 'json',
success: function (data) {
$(data).each(function (index, item) {
$yearDropDownList.append($('<option/>', { value: item, text: item }));
});
}
});第二个是根据yearDropDownList的变化填充的。它正在命中方法并返回数据,但是当我单击select时,一切都是空白的。这里只有<option></option>
以下是变化:
$yearDropDownList.on('change', function(e) {
$.ajax({
url: $makeDropDownList.attr('data-request-url'),
method: 'GET',
dataType: 'json',
data: { year: $yearDropDownList.find(':selected').text() },
success: function (data) {
$(data).each(function(index, item) {
$makeDropDownList.append($(<option/>")).val(index).text(item);
});
}
});
});发布于 2015-10-31 04:17:37
$makeDropDownList.append($(<option/>")).val(index).text(item);您正在创建一个空白option,并且未在其上设置val和text。
将其更改为您在第一个调用中的方式:-
$makeDropDownList.append($('<option/>', { value: index, text: item}));或者将第二个括号移到右边,将选项移到末尾,然后修复1个双引号。
$makeDropDownList.append($('<option/>').val(index).text(item)); https://stackoverflow.com/questions/33444126
复制相似问题