获取TypeError: undefined不是handsontable.validateCells()上的函数
Getting TypeError: undefined is not a function on handsontable.validateCells()
在调用Handsontable
的validateCells()
方法时出现以下错误。
我的代码:http://jsfiddle.net/o7w1ybjy/
html<div id="example1" class="hot handsontable htColumnHeaders"></div>
</style><!-- Ugly Hack due to jsFiddle issue -->
<script src="http://docs.handsontable.com/0.16.1/scripts/jquery.min.js"></script>
<script src="http://docs.handsontable.com/0.16.1/bower_components/handsontable/dist/handsontable.full.js"></script>
<link type="text/css" rel="stylesheet" href="http://docs.handsontable.com/0.16.1/bower_components/handsontable/dist/handsontable.full.min.css">
javscript
document.addEventListener("DOMContentLoaded", function() {
var people = [
{id: 1, name: {first: 'Joe', last: 'Fabiano'}, ip: '0.0.0.1', email: 'Joe.Fabiano@ex.com'},
{id: 2, name: {first: 'Fred', last: 'Wecler'}, ip: '0.0.0.1', email: 'Fred.Wecler@ex.com'},
{id: 3, name: {first: 'Steve', last: 'Wilson'}, ip: '0.0.0.1', email: 'Steve.Wilson@ex.com'},
{id: 4, name: {first: 'Maria', last: 'Fernandez'}, ip: '0.0.0.1', email: 'M.Fernandez@ex.com'},
{id: 5, name: {first: 'Pierre', last: 'Barbault'}, ip: '0.0.0.1', email: 'Pierre.Barbault@ex.com'},
{id: 6, name: {first: 'Nancy', last: 'Moore'}, ip: '0.0.0.1', email: 'Nancy.Moore@ex.com'},
{id: 7, name: {first: 'Barbara', last: 'MacDonald'}, ip: '0.0.0.1', email: 'B.MacDonald@ex.com'},
{id: 8, name: {first: 'Wilma', last: 'Williams'}, ip: '0.0.0.1', email: 'Wilma.Williams@ex.com'},
{id: 9, name: {first: 'Sasha', last: 'Silver'}, ip: '0.0.0.1', email: 'Sasha.Silver@ex.com'},
{id: 10, name: {first: 'Don', last: 'Pérignon'}, ip: '0.0.0.1', email: 'Don.Pérignon@ex.com'},
{id: 11, name: {first: 'Aaron', last: 'Kinley'}, ip: '0.0.0.1', email: 'Aaron.Kinley@ex.com'}
],
example1 = document.getElementById('example1'),
example1console = document.getElementById('example1console'),
settings1,
ipValidatorRegexp,
emailValidator;
ipValidatorRegexp = /^(?:'b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'b|null)$/;
emailValidator = function (value, callback) {
setTimeout(function(){
if (/.+@.+/.test(value)) {
callback(true);
}
else {
callback(false);
}
}, 1000);
};
settings1 = {
data: people,
beforeChange: function (changes, source) {
for (var i = changes.length - 1; i >= 0; i--) {
// gently don't accept the word "foo" (remove the change at index i)
if (changes[i][3] === 'foo') {
changes.splice(i, 1);
}
// if any of pasted cells contains the word "nuke", reject the whole paste
else if (changes[i][3] === 'nuke') {
return false;
}
// capitalise first letter in column 1 and 2
else if ((changes[i][1] === 'name.first' || changes[i][1] === 'name.last') && changes[i][3].charAt(0)) {
changes[i][3] = changes[i][3].charAt(0).toUpperCase() + changes[i][3].slice(1);
}
}
},
afterChange: function (changes, source) {
if (source !== 'loadData') {
example1console.innerText = JSON.stringify(changes);
}
},
colHeaders: ['ID', 'First name', 'Last name', 'IP', 'E-mail'],
columns: [
{data: 'id', type: 'numeric'},
{data: 'name.first'},
{data: 'name.last'},
{data: 'ip', validator: ipValidatorRegexp, allowInvalid: true},
{data: 'email', validator: emailValidator, allowInvalid: true}
]
};
var hot = new Handsontable(example1, settings1);
function bindDumpButton() {
if (typeof Handsontable === "undefined") {
return;
}
Handsontable.Dom.addEvent(document.body, 'click', function (e) {
var element = e.target || e.srcElement;
if (element.nodeName == "BUTTON" && element.name == 'dump') {
var name = element.getAttribute('data-dump');
var instance = element.getAttribute('data-instance');
var hot = window[instance];
console.log('data of ' + name, hot.getData());
}
});
}
bindDumpButton();
hot.validateCells();
});
Uncaught TypeError: undefined不是函数handsontable.full.js: 4279 validatorsqueue.checkifqueueisemptyhandsontable.full.js: 4279 validatorsqueue.removevalidatorformqueuehandsontable.full.js: 4273(匿名函数)handsontable.full.js: 4814完成handsontable.full.js: 4383(匿名的函数)handsontable.full.js:4398(匿名函数)
您正在调用hot.validateCells()而没有回调,这就是导致问题的原因。
查看handsontable.full.js中的以下方法:
function ValidatorsQueue() {.....}
this.validateCells = function(callback) {....}
可能与此问题有关:https://github.com/handsontable/handsontable/issues/933
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 将函数的上下文应用于javascript变量
- 如何在JavaScript中将字符串转换为函数引用
- 用嵌套函数和默认函数定义函数
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 无法导出函数expressjs/requestjs中的变量
- 函数参数中的数据与指定变量之间的任何性能差异
- JQuery合并了keyup和focusout两个函数
- ES6构造函数返回基类的实例
- 监视函数从服务返回不起作用,但作用域函数起作用
- 我可以在json对象中添加一个函数吗
- AngularJS:我可以跳过函数参数回调吗
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- JavaScript数组排序(函数)用于对表行进行排序,而不是排序
- jquery点击函数select&取消选择
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- Node.js v6.2.0类扩展不是函数错误
- 比较从函数和生成的日期对象
- jQuery中是否内置了任何字符串格式化函数
- 获取TypeError: undefined不是handsontable.validateCells()上的函数