<script type="text/javascript">
var initialData = @Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model.categoryAllocations));
var categoryAllocation = function(item)
{
var self = this;
self.des_AllocationCategoryText = ko.observable(item.des_AllocationCategoryText);
self.des_AllocationAmount = ko.observable(item.des_AllocationAmount);
};
var viewModel = function(){
var self = this;
debugger
self.categoryAllocations = ko.observableArray($.each(initialData,function (i, item) {
debugger
new categoryAllocation(item);
}));
self.sum = ko.computed(function(){
var total = 0;
debugger
$.each(self.categoryAllocations(), function(i, item) {
debugger;
total += item.des_AllocationAmount;
})
return total;
})
};
$(document).ready(function ()
{
ko.applyBindings(new viewModel());
});
function formatCurrency(value) {
return "$" + value.toFixed(2);
}
</script>
<table>
<thead class="k-grid-header">
<tr class="">
@*<th></th>*@
<th>Category</th>
<th>Amount</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody data-bind='foreach: categoryAllocations'>
<tr>
<td><span data-bind='text: des_AllocationCategoryText' />
</td>
<td>
<input data-bind='value: des_AllocationAmount, valueUpdate: "afterkeydown" '/>
</td>
</tr>
</tbody>
</table>
<p class='grandTotal'>
Total value: <span data-bind='text: formatCurrency(sum())'></span>
</p>
Can someone help me in point out the bug in my code
Thanks in Advance,
Naren