Need help with bidnings in Knockout. Im totaly newbiew on knockout. Have tried to toubleshoot by firebug without result.
Here is my example
This is the Knockout ViewModel
function MarketViewModel() {
var self = this;
self.markets = ko.observableArray();
var baseUri = 'api/market';
$.getJSON(baseUri, self.markets);
}
$(document).ready(function () {
ko.applyBindings(new MarketViewModel());
})
The API controller that returning the array as json works perfectly btw.
And my view
<!-- Default datatable -->
<div class="block well">
<div class="navbar">
<div class="navbar-inner">
<h5>Default datatable</h5>
</div>
</div>
<div class="table-overflow">
<table class="table table-striped" id="data-table">
<thead>
<tr>
<th>Marknad</th>
</tr>
</thead>
<tbody data-bind="forech: markets">
<tr>
<td data-bind="text: description"></td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- /default datatable -->
@section scripts
{
<script src="~/Scripts/vm/MarketViewModel.js"></script>
}
UPDATE
Error from firebug: Error: Unable to parse bindings. Message: ReferenceError: description is not defined; Bindings value: text: description This throws Unable to parse binding on the property "description" in view. But the JSON result contains properties for description.
Json array:
[{"$id":"1","MarketId":14,"Description":"SE Projektutveckling","ChUser":"anders.persson","ChTime":"2013-01-28T09:07:50.067"},{"$id":"2","MarketId":39,"Description":"SE Styckehus","ChUser":"anders.persson","ChTime":"2013-01-21T23:01:04.637"},{"$id":"3","MarketId":40,"Description":"NO Styckehus","ChUser":"anders.persson","ChTime":"2013-01-21T23:00:58.01"},{"$id":"4","MarketId":41,"Description":"GB Styckehus","ChUser":"anders.persson","ChTime":"2013-01-21T23:00:50.933"},{"$id":"5","MarketId":42,"Description":"DE Styckehus","ChUser":"anders.persson","ChTime":"2013-02-05T09:39:57.03"},{"$id":"6","MarketId":43,"Description":"SE Fritidshus","ChUser":"anders.persson","ChTime":"2013-01-21T23:00:24.597"}]
$.getJSON(baseUri, function(data) { console.log(data);self.markets(data)});)? Also there is typo in yourdata-bind="forech: markets"it should bedata-bind="foreach: markets". Also the casing of the properties matters make sure that the result contains the propertydescriptionand notDescription- nemesv