我在定义的对象上有一个子可观察数组。当来自服务器的对象被返回并填充到淘汰赛 observable 中时,数据无法显示。但是可以通过调试来验证视图模型中的数据。我创建了说明问题的 jsFiddle。
http://jsfiddle.net/CraigHead/Y2Fr6/
我的视图模型是这样定义的
function PropertyLease(propertyLeaseId, propertyCatalogId, confirmedBldgSF, leaseExpenseStructure, leaseTermRate, propertyType, yearBuilt)
{
var self = this;
self.PropertyLeaseId = ko.observable(propertyLeaseId);
self.PropertyCatalogId = ko.observable(propertyCatalogId);
self.ConfirmedBldgSF = ko.observable(confirmedBldgSF);
self.LeaseExpenseStructure = ko.observable(leaseExpenseStructure);
self.LeaseTermRate = ko.mapping.fromJS(leaseTermRate);
self.PropertyType = ko.observable(propertyType);
self.YearBuilt = ko.observable(yearBuilt);
}
function PropertyLeaseTermRate(propertyLeaseTermId, propertyLeaseId, from, to, annualRatePSF)
{
var self = this;
self.PropertyLeaseTermId = ko.observable(propertyLeaseTermId);
self.PropertyLeaseId = ko.observable(propertyLeaseId);
self.From = ko.observable(from);
self.To = ko.observable(to);
self.AnnualRatePSF = ko.observable(annualRatePSF);
}
当数据从服务器返回时我会更新它们
viewModel.LeaseSearchResults.removeAll();
var vmLeaseSearchResults = viewModel.LeaseSearchResults();
for(var idx = 0; idx<result.LeaseSearchResults.length; idx++){
var data = result.LeaseSearchResults[idx];
vmLeaseSearchResults.push(
new PropertyLease(
data.PropertyLeaseId,
data.PropertyCatalogId,
data.ConfirmedBldgSF,
data.LeaseExpenseStructure,
data.LeaseTermRate,
data.PropertyType,
data.YearBuilt
)
)
}
viewModel.LeaseSearchResults.valueHasMutated();
我不确定我做错了什么?精氨酸!
PropertyLeaseTermRate
PS在用户从数据网格中做出选择之前,不会使用第二个视图模型。;-) 很抱歉让您感到困惑。