녹아웃 관측 가능한 배열을 사용하여 드롭 다운 목록을 채 웁니다. 배열 값을 하드 코딩하면 드롭 다운 목록이 채워집니다. 이제 데이터베이스에서 데이터를 가져 오려고합니다. JSON 형식을 사용하고 있습니다. 자바 스크립트 개체의 단일 속성에 액세스하고 있습니다. 즉, 인증 및 나는 다시 스크립트로 전달 오전 배열을 만드는 중입니다.하지만 때마다 배열은 콘솔에 표시되는 반면에 전달되는 값은 정의되지 않습니다.Javascript 개체를 자바 스크립트로 변환
내가 사용하고 배열로 변환하는 코드는
var getCertifications = function() {
$.ajax({
type : "GET",
async : false,
url : "/Provider/GetCertifications",
dataType : "json",
success: function (data) {
var arrCertification = [];
$.each(data, function (i, item) {
arrCertification.push((item.Certification));
});
return arrCertification;
},
error : function() {
alert(" An error occurred.");
}
});
};
녹아웃 관찰 가능한의 코드는
var certificates = getCertifications();
self.certificationArray = ko.observableArray(certificates);
입니다과 HTML은
<div class="form-group">
<label class="col-sm-2 control-label labelfont">Certification:</label>
<div class="col-sm-6">
<select class="form-control" id="certification" name="certification" data-bind="value: certification, options: certificationArray, optionsCaption: 'Select a Certification'">
</select>
</div>
</div>
수있는 몇 가지입니다 하나는 내가 잘못 가고있는 곳에서 나를 안내 해주십시오.
성공한 부분의 결과가 나오지 않습니다. 불편을 끼쳐 드려 죄송합니다. Ajax와 Jquery에 새로 왔습니다. –
아무 것도하지 않습니다. 컨트롤은 이미이 지점에서 기능을 벗어났습니다. AJAX 호출은 비동기식이므로 서버가 결과를 반환하면 성공은 언젠가 나중에 호출됩니다. –
async : false로 설정하면 동기화되지 않습니다. –