在 knockout 中,这有效并正确绑定(bind):
self.currentCustomer = ko.observable(new Customer("a","b","c","d","e","f","g","h"));
但是,下面没有。
// Random list of customers
self.customers = ko.observableArray([
new Customer("a","b","c","d","e","f","g","h")
]);
self.currentCustomer = ko.observable(self.customers[0]);
我不明白为什么这不起作用。这种模式在我的应用程序的其他部分正常工作。
最佳答案
要访问数组,您必须解包它:
self.currentCustomer = ko.observable(self.customers()[0]);
关于javascript - Knockout.js - ObservableArray 不返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13617437/