I'm using the latest KO Mapping Plugin. The idea is the Details section should be populated with JSON data retrieved from Ajax Call.
var supervisorVM = {
supervisor: ko.observable()
};
-----------code to call custom data service which returns JSON---
if (supervisorDetails) {
$('#Detail').show();
supervisorVM.supervisor = ko.mapping.fromJS(supervisorDetails);
ko.applyBindings(supervisorVM, document.getElementById("Detail"));
}
<div id="Detail" class="side-widget" style="display:none">
<h2>Details</h2>
<strong>
Supervisor<br>
<span data-bind="text: supervisor.FullName"></span><br/>
</strong>
<span data-bind="text: supervisor.PhoneNumber"></span><br/>
<a data-bind="text: supervisor.Email, attr: { href : 'mailto:'+supervisor.Email() }"></a>
</div>
Everytime I run the Detail section doesn't get populated with supervisor details i.e. Fullname and Phone Number.
I debugged and confirmed that supervisorVM.supervisor is populated but data bind doesn't work.
Also tried below no luck:
supervisorVM.supervisor(ko.mapping.fromJS(supervisorDetails));
I spent more than 2 hours already, can someone please help what have I done wrong?
Thanks.