无法读取外部 viewmodel.js 中未定义的 属性 'fromJS'
cannot read property 'fromJS' of undefined in external viewmodel.js
我不断收到错误消息:未捕获类型错误:无法读取未定义的 属性 'fromJS'
这个想法是有 2 个页面,其中 ui 表示,另一个是 het viewmodel。
我有 2 页:
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>
和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 || {}));
我做错了什么/遗漏了什么?
谢谢
问题已解决。问题是
<script src="bin/knockout.mapping-latest.js" type="text/html"></script>
更改为:
<script src="bin/knockout.mapping-latest.js"></script>
起飞:type="text/html"
我不断收到错误消息:未捕获类型错误:无法读取未定义的 属性 'fromJS' 这个想法是有 2 个页面,其中 ui 表示,另一个是 het viewmodel。 我有 2 页:
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>
和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 || {}));
我做错了什么/遗漏了什么?
谢谢
问题已解决。问题是
<script src="bin/knockout.mapping-latest.js" type="text/html"></script>
更改为:
<script src="bin/knockout.mapping-latest.js"></script>
起飞:type="text/html"