ko.observablearray があります。サーバーから取得した値を入力しています。
self.AllItems = ko.observableArray([]);
$.getJSON('/Controller/GetItems', function (data) {
for (var index = 0; index < data.length; index++) {
self.AllItems.push(data[index]);
}
};
});
リストにバインドされた配列があり、すべてのアイテムが含まれているため、これがうまく機能することはわかっています。
<select multiple="multiple" size='4' data-bind="options:$root.AllItems, selectedOptions:$root.ItemsSelectValue"> </select>
ただし、後で AllItems の要素にアクセスすることはできません。
alert(self.AllItems().length);
-- 0 を返します
alert(self.AllItems());
-- 何も返さない
助けてください。