I'm trying to build view using knockout and jquery.tmpl. I'm using template, to build a table, but seems that I can't properly pass data to template. Here is my knockout ViewModel :
function ChargeModel() {
self = this;
self.Name = ko.observable("Ignar");
self.Record = ko.observableArray([]);
self.refresh = function () {
$.ajax({
url: "@Url.HttpRouteUrl("DefaultApi", new { controller = "KnockoutApi", action = "ShippingCharge" })",
type: 'GET',
dataType: 'json',
success: function (result) {
var mapped = ko.mapping.fromJS(result);
self.Record(mapped);
},
error: function (result) {
alert("smth bad happened");
}
})
}
self.refresh();
};
In HTML :
<table class="table table-hover" data-bind="template: { name: 'peopleList' }"></table>
And template code :
<script type="text/html" id="peopleList">
<thead>
<tr>
<th>Zone</th>
<th>${Name} </th>
<th>${$root.Record.Name}</th>
</tr>
</thead>
Also, I've checked my data with simple knockout data-bind, and it turns, that I can't simply access to my observable like :
<label data-bind="text: Record.Name"></label>
it can be accessed like this :
<label data-bind="text: Record().Name"></label>
P.S. I've checked JSON, it is valid and it contains property "Name"