Reputation: 979
I keep getting the error : Uncaught TypeError: Cannot read property 'fromJS' of undefined The idea is to have 2 pages, where is the the ui representation and the other one is het viewmodel. I have 2 pages:
Index.html
<link rel="stylesheet" href="bin/styles/kendo.common.min.css" />
<link rel="stylesheet" href="bin/styles/kendo.default.min.css" />
<link rel="stylesheet" href="bin/styles/kendo.dataviz.min.css" />
<link rel="stylesheet" href="bin/styles/kendo.dataviz.default.min.css" />
<script src="bin/js/jquery.min.js"></script>
<script src="bin/js/kendo.all.min.js"></script>
<script src="bin/knockout-3.2.0.js"></script>
<script src="bin/knockout.mapping-latest.js" type="text/html"></script>
<script src="IndexViewModel.js"></script>
<script>
$(function() {
var indexVM = new IndexViewModel.ViewModel();
ko.applyBindings(indexVM);
});
</script>
<table>
<thead><tr>
<th>First Name</th>
</tr></thead>
<tbody data-bind="foreach: Users">
<tr>
<td data-bind="text: UserName"/></td>
</tr>
</tbody>
</table>
and IndexViewModel.js :
var IndexViewModel = (function (IndexViewModel) {
IndexViewModel.ViewModel = function() {
var self = this;
self.Users = ko.observableArray();
$.ajax({
url : 'GetUsers.php',
dataType: 'json',
success: function(data){ //json string of the student records returned from the server
self.Users = ko.mapping.fromJS(result.data, {}, self.Users);
}
});
}
return IndexViewModel;
}(IndexViewModel || {}));
What am I doing wrong / missing?
Thanks
Upvotes: 1
Views: 5338
Reputation: 979
Solved the issue. Problem was
<script src="bin/knockout.mapping-latest.js" type="text/html"></script>
changed to :
<script src="bin/knockout.mapping-latest.js"></script>
Taking off : type="text/html"
Upvotes: 3