0
jQuery를 사용하여 Option 요소를로드하고 있고 선택한 옵션을 설정하려고하면 작동하지 않습니다. 누군가 내가 그것을 고치기 위해 바꿀 필요가있는 것을 보여줄 수 있습니까?jQuery를 사용하여 선택한 옵션 설정
HTML
<select data-placeholder="Program View" class="chosen-select"></select>
jQuery를
$.getJSON(path)
.done(function (data) {
if (!data) {
return
}
setTimeout(
function() {
var loadedAtLeastOneProgram = false;
$.each(data, function (i, val) {
if (val.Value.toLowerCase() != "rt") {
loadedAtLeastOneProgram = true;
$('.chosen-select').append('<option value="' + val.Value + '">' + val.Value + '</option>')
}
})
$('.chosen-select').trigger('chosen:updated');
if (!loadedAtLeastOneProgram) {
$("#programsDataItems").append("<li><a href='#'>No Tailored Programs Available</a></li>");
}
// After loading (or reloading) the programs, see if one was previously selected. The user may have refreshed their browser.
// In another part of my application, I set the "CurrentProgram"
var program = retrieveStorageItem("CurrentProgram");
if (program == null || program == undefined) {
program = "rt";
} else {
// ***** This is the part that does not work. Nothing shows as selected. ******
$(".chosen-select").val(program).prop('selected', true);
}
}, 50);
})
.fail(function (e) {
// Adding logging for errors.
});
'