簡體   English   中英

使用Knockout將optionsText綁定到包含對象數組的屬性?

[英]Bind optionsText to property with an array of objects using Knockout?

我有一個存儲內部對象的數組observableArray在Knockout.js,和我想要綁定的對象來的屬性之一optionsText具有約束力select元素,但是,這是行不通的選項是不被顯示。

observableArray最初是空白的,並由AJAX請求填充:

self.currentPeople = ko.observableArray([]);

在AJAX請求之后,我可以在console.log查看並收到以下內容:

console.log(self.currentPeople);
// Produces [Object, Object] where each of the objects have properties of `personId` and `personName`

然而,我的選擇下拉列表仍未填充:

<select class="large-3" data-bind="options: currentPeople, optionsText: 'personName', optionsValue: 'personId', optionsCaption: 'All',  value: currentPerson"></select>

只顯示“全部”。 有任何想法嗎?

如果console.log(self.currentPeople)顯示您的對象數組,則意味着您(錯誤地)使用賦值填充它而不是將其作為函數調用。

將其填充為:

self.currentPeople(newData);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM