ko.mapping.fromJS行の後に、これが未定義のviewModelをもたらした理由を見つけるための最良の方法は何ですか?
rawJSONは、chromejsオブジェクトエクスプローラーで正常に表示されます
var viewModel = ko.mapping.fromJS(rawJSON);
viewModel = decorateViewModel(viewModel);
ko.applyBindings(viewModel);
Chromeで表示:
rawJSON: Object
Companies: Array[1]
CompaniesFollowing: Array[0]
DisplayName: null
DateCreated: "2013-03-11T21:50:21.9"
__proto__: Object
viewModel: undefined
function decorateViewModel(viewModel){
viewModel.CompaniesFollowing().forEach(function(self) {
self.isFollowing = ko.observable(true);
self.toggleIsFollowing = function () {
if(self.isFollowing()){
unFollowCompany()}
else{
followCompany();
}
self.isFollowing(!self.isFollowing());//reverse it so the user can see the button text change
};
self.followButtonText = ko.computed(function () {
return self.isFollowing() ? "Unfollow" : "Follow";
});
self.styleClass = ko.computed(function () {
return self.isFollowing() ? "radius button" : "radius secondary button";
});
});
rawJSON:
var rawJSON = { "Companies" : [ { "DateCreated" : "2013-03-11T21:53:31.123",
"Description" : "eee",
"EquityOffered" : 3.0,
"FollowingUsers" : null,
"Id" : 1,
"InvestmentFound" : 0.0,
"InvestmentSought" : 3333.0,
"LogoFileName" : "4ED564E6-CDBB-4045-8E55-9581B7FA13E0.jpg",
"Name" : "Model Adapt",
"SocialDetails" : null
} ],
"CompaniesFollowing" : [ ],
"DateCreated" : "2013-03-11T21:50:21.9",
"DateUpdated" : "2013-03-11T21:50:21.9",
"DisplayName" : null,
"FullName" : null,
"HomeAddress" : null,
"Id" : 1,
"Investor" : { "AvailableFunds" : 0.0,
"DateCreated" : "2013-03-11T22:30:07.273",
"DateUpdated" : "2013-03-11T22:30:07.273",
"Description" : "kbibkb",
"FollowingUsers" : [ ],
"Id" : 1,
"Interests" : "bukb",
"LogoFileName" : null,
"Name" : "giu",
"Skills" : "kbku",
"SocialDetails" : null
},
"InvestorsFollowing" : [ { "AvailableFunds" : 0.0,
"DateCreated" : "2013-03-11T22:30:07.273",
"DateUpdated" : "2013-03-11T22:30:07.273",
"Description" : "kbibkb",
"FollowingUsers" : [ ],
"Id" : 1,
"Interests" : "bukb",
"LogoFileName" : null,
"Name" : "giu",
"Skills" : "kbku",
"SocialDetails" : null
} ],
"LogoFileName" : null,
"MiniAbout" : null,
"UserName" : "Master_"
}