我在页面上有一个下拉列表。我在下拉列表中敲出了数据绑定。用AJAX填充后在敲除下拉列表中设置选定的值
默认情况下,下拉列表中没有任何项目。我有一个工作的AJAX调用,并为下拉列表检索正确的项目列表。
在项目列表已被检索并加载到下拉列表中后,如何设置下拉列表中的选定项目?
<select class="form-control" data-bind="options: listOfPossibleValues, value: selectedValue, optionsCaption: 'Select a Value'"></select>
$.ajax({
type: 'GET',
dataType: 'json',
url: url,
data: {
someParameter: someParameterValue
},
success: function (response) {
$.each(response, function (index, center) {
self.listOfPossibleValues.push(response[index]);
});
},
error: function (xhr, ajaxOptions, thrownError) {
console.log("There has been an error retrieving the values.");
}
});