I have a child observable array on an defined object. When the object from the server is returned and populated into the knockout observable the data fails to display. However the data is in the view model can can be verified with debugging. I have created jsFiddle that illustrates the problem.
http://jsfiddle.net/CraigHead/Y2Fr6/
My view models are defined as such
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);
}
and I update them when the data is returned from the server like
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();
I am not sure what I am doing wrong? Arg!
P.S. The second View Model PropertyLeaseTermRate isn't used until the user makes a choice from a data grid. ;-) Sorry for the confusion there.