无法读取属性'来自JS'外部viewmodel.js中未定义的
cannot read property 'fromJS' of undefined in external viewmodel.js
我一直收到错误:未捕获类型错误:无法读取未定义的属性"fromJS"这个想法是有两个页面,其中是ui表示,另一个是视图模型。我有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"
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 使用agility.js进行页面布局和合成
- 使用Clipboard.js复制span文本
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- '型号'和'ViewModel'在Knockout.js中
- 将MVC ViewModel转换为外部.js文件中的Javascript对象
- 无法读取属性'来自JS'外部viewmodel.js中未定义的
- viewModel 使用挖空.js在原型上计算函数
- 挖空.js数据绑定到 ViewModel
- 在Knockout.js中,如何在映射后根据复选框字段对viewModel项进行排序
- Knockout.js选项绑定在ViewModel中不起作用
- Knockout.js:从模型中分离ViewModel逻辑
- 从MVC3服务器端为backbone.js传递ViewModel
- 什么是最好的ViewModel javascript文件组织,与asp.net mvc和knockout js库一起工作
- 将ViewModel映射到JS对象
- 在不使用全局变量的情况下重用knockout.js的viewModel
- 从js函数在razor视图上填充viewmodel属性
- Knockout JS - viewModel access
- Knockout JS-为什么所有的例子都只包含ViewModel/View而没有Model
- 如何将 HTML 添加到此 Knockout.js Viewmodel 变量中