I'm very new to Knockout JS. I haven't found much help through Google on mapping with knockout js. I have a JSON coming in from the server. I map the JSON with the knockout js mapping library. The data-binded dom associated with the property does not update. I have included a fiddle of the script im using. Notice the json object that gets mapped into the observable. When the load button is clicked, the json is mapped and the value of the property "test" is supposed to show up in the tag. Any ideas why its not showing up in the tag?
There is a working example in the JS fiddle.
This is the JSON that is being mapped
var json = {
"id": 9,
"test": "John Doe",
"firstName": "John",
"lastName": "Doe",
"referenceNumber": "BUY-08",
"position": "Buyer",
"type": "Buyer",
"telephone": "028 82 240780",
"email": "m@email.com",
"departmentId": 3,
"departmentName": "DEPT B",
"country": "United Kingdom"
};
My Example Script
var masterModel = function()
{
var self = this;
self.members = ko.observableArray([]);
self.websites = ko.observableArray([]);
self.seoData = ko.observable();
self.test = ko.observable();
self.loadWebsite = function(website)
{
var json = {
"id": 9,
"test": "John Doe",
"firstName": "John",
"lastName": "Doe",
"referenceNumber": "BUY-08",
"position": "Buyer",
"type": "Buyer",
"telephone": "028 82 240780",
"email": "m@email.com",
"departmentId": 3,
"departmentName": "DEPT B",
"country": "United Kingdom"
};
self.test(ko.mapping.fromJS(json))
console.log(self.test);
}
}
var master = new masterModel();
ko.applyBindings(master);
The problem is when you click on the loadWebsite the $data.test.test is not updating!