未捕获的类型错误:未定义不是函数淘汰 js
Uncaught TypeError: undefined is not a function knockout js
我正在尝试将某些数据添加到数组中,如下所示:
这是我的代码:-
创建.html
字段名称: 显示名称: 添加字段 </fieldset>
<table class="table" style="margin:20px 0px">
<thead>
<tr>
<th>Field Name</th>
<th>Field Display Name</th>
</tr>
</thead>
<tbody data-bind="foreach: fields">
<tr>
<td data-bind="text: fieldName"></td>
<td data-bind="text: fieldDisplayName"></td>
<td>
<div style="height:20px; width:20px; border:1px solid #000000; padding: 5px" data-bind="style: { backgroundColor : color }"></div>
</td>
<td><button class="btn btn-danger btn-circle" data-bind="click: remove"><i class="glyphicon glyphicon-remove"></i></button></td>
</tr>
</tbody>
</table>
表.js
var ViewModel = function () {
var self = this;
self.fields = ko.observableArray();
self.fieldName = ko.observable();
self.fieldDisplayName = ko.observable();
self.isRangeError = ko.observable(false);
var Field = function (fieldName, fieldDisplayName) {
this.fieldName = fieldName;
this.fieldDisplayName = fieldDisplayName;
this.remove = function () {
self.fields.remove(this);
}
}
self.addFields = function () {
var tr = self.fields();
for (var i = 0; i < tr.length; i++) {
if (self.fieldName == tr[i].fieldName && self.fieldDisplayName == tr[i].fieldDisplayName) {
self.isFieldError(true);
return;
}
}
self.isFieldError(false);
self.fields.push(new Field(self.fieldName(), self.fieldDisplayName()));
}
我收到这样的错误:-
Uncaught TypeError: undefined is not a functionTableChart.js:41 self.addFieldsknockout-3.2.0.debug.js:3713 (anonymous function)jquery-1.10.2.js:5109 jQuery.event.dispatchjquery-1.10.2.js:4780 elemData.handle
我该如何解决这个问题?我对淘汰赛和javascript很陌生。任何帮助,不胜感激。
您声明的可观察量有问题。
self.isRangeError = ko.observable(false);
应该是:
self.isFieldError = ko.observable(false);
此外,颜色不是在模型上定义的,而是在表中使用的。
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 如何在JavaScript中将字符串转换为函数引用
- 用嵌套函数和默认函数定义函数
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- JQuery合并了keyup和focusout两个函数
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 保存淘汰函数时如何处理原型
- 淘汰抛出消息:类型错误:
不是一个函数.什么意思 - 如何在 SharePoint 上向此淘汰 JavaScript 添加额外的列表函数
- 将数据绑定参数传递给函数淘汰
- 未捕获的类型错误:未定义不是函数淘汰 js
- 在加载时淘汰JS调用函数
- 在范围之外调用 AJAX 成功的淘汰模型函数
- 淘汰dom操作后回调jquery函数