我在頁面上有一個下拉列表。我在下拉列表中敲出了數據綁定。用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.");
}
});