0
我沒有收到任何錯誤,但由於某種原因(可能很簡單)我無法獲得值顯示在我的下拉列表中。剔除js下拉列表不顯示我的綁定在一個foreach
我的淘汰賽VM:
function UserRecruitingViewModel(apiBaseUrl, userId) {
var self = this;
self.orgs = ko.observableArray();
//ddl org view switcher stuff
self.orgDdl = ko.observableArray();
self.selectedOrg = ko.observable();
var DropdownOrg = function (name, guid) {
this.orgName = name;
this.orgId = guid;
};
//pull initial data
$.getJSON(apiBaseUrl + "?userId=" + userId, function (data) {
//alert(data);
$.each(data, function() {
//alert(data);
var dropdownOrg = new DropdownOrg();
var org = new Organization();
$.each(this, function (k, v) {
//alert("in foreach");
if (k == "UserGuid") {
org.userGuid = v;
}
if (k == "OrgGuid") {
dropdownOrg.orgId = v;
org.orgGuid = v;
}
if (k == "OrgName") {
dropdownOrg.name = v;
org.orgName = v;
}
if (k == "IsHiring") {
org.isHiring = v;
}
if (k == "Blurb") {
org.blurb = v;
}
//alert("k var: "+k); //field name
//alert("v var "+v); //field value
//alert("data var " + data); //array of objects (3)
//alert(org);
});
alert("ddl " + dropdownOrg.name);
self.orgDdl.push(dropdownOrg);
self.orgs.push(org);
});
});
}
在alert("ddl " + dropdownOrg.name)
我看到正確的價值觀。 在我的網頁我有這樣的:
<ul class="list-unstyled" data-bind="foreach: orgs">
<div class="row">
<div class="col-md-6">
<p>
Viewing:
<select class="form-control"
data-bind="options: $parent.orgDdl(), optionsText: orgName, value: orgGuid, optionsCaption: 'Change...'"></select>
</p>
...snip...
當我拉起頁面在瀏覽器中,我得到顯示正確數據的警報,但在DDL我看到4個選項:「更改...」和3空白選項。檢查顯示值的元素不在那裏。
任何想法,我搞亂語法?