在http://jsfiddle.net/gZC5k/1004/處緩慢擴展我的嵌套表單我正在運行ko.computed,我想用它來計算嵌套JSON數組中的子數。打破的代碼是//此破解基於計算可觀察數據在陣列長度上的敲除模型
self.contacts = ko.observableArray(ko.utils.arrayMap(contacts, function (contact) {
return {
firstName: ko.observable(contact.firstName),
lastName: ko.observable(contact.lastName),
isKey: ko.observable(contact.isKey),
gender: ko.observable(contact.gender),
phones: ko.observableArray(ko.utils.arrayMap(contact.phones, function (phone) {
return {
type: ko.observable(phone.type),
number: ko.observable(phone.number),
calls: ko.observableArray(phone.calls),
callsVisible: ko.observable(false)
};
})),
addresses: ko.observableArray(contact.addresses),
optionGender: optionGender,
phonesVisible: ko.observable(false),
addressesVisible: ko.observable(false),
// this breaks
// numberOfPhones: ko.computed(function (contact) {
// return contact.phones.length;
// });
};
}));
錯誤在哪裏?
保羅,thx 4你的建議,不幸的是它沒有工作。對於我應該在哪裏定義函數,我也有我的懷疑。 – Graphileon 2013-02-26 14:47:08
有沒有錯誤,或者它只是不顯示正確的值? – 2013-02-26 14:54:41
它打破了代碼..在jsfiddle它現在被註釋掉,否則數據不會加載 – Graphileon 2013-02-26 15:00:09