当使用requirejs对Handsontable进行擦除时,我一直得到以下错误和堆栈跟踪
Uncaught TypeError: undefined is not a function VM18361 handsontable.full.js:20729
unformatNumeral VM18361 handsontable.full.js:21325
numeral.fn.Numeral.unformat VM18361 handsontable.full.js:21325
numeral VM18361 handsontable.full.js:21037即使在http://handsontable.com/的示例中也会发生这种情况。
我的所需配置和使用handsontable的模块如下所示
require.config({
paths: {
handsontable : '/js/dependencies/handsontable.full'
},
shim: {
'handsontable': {
deps: ['jquery'],
exports: 'Handsontable'
}
}
define(['handsontable'], function(Handsontable) {
var data = [
['', 'Maserati', 'Mazda', 'Mercedes', 'Mini', 'Mitsubishi'],
['2009', 0, 2941, 4303, 354, 5814],
['2010', 3, 2905, 2867, 412, 5284],
['2011', 4, 2517, 4822, 552, 6127],
['2012', 2, 2422, 5399, 776, 4151]
];
var container = document.getElementById('example');
var config = {
data: data,
minSpareRows: 1,
colHeaders: true,
contextMenu: true
};
var hot = new Handsontable(container, config);
});还有其他人遇到过这个问题吗?
目前,我看到的唯一解决方案是将handsontable作为全局对象(绕过管理依赖项的需求的全部目的)。
我希望有一个更好的解决方案。
谢谢!
发布于 2016-01-12 15:29:00
我认为这里的问题是,您使用的是Handsontable的完整版本,其中包括依赖项,如Numeral.js。由于有些依赖项是符合AMD的,即调用define(),所以最终只能引用Numeral.js而不是Handsontable。
要正确使用它,只需使用裸发行版文件handsontable.js,并包含该版本的Handsontable所需的所有依赖项。就像这样:
require.config({
paths: {
handsontable : '/js/dependencies/handsontable'
},
shim: {
'handsontable': {
deps: ['moment', 'pikaday', 'zeroclipboard'],
exports: 'Handsontable'
}
}
})我不确定您使用的是哪个版本的Handsontable,当前版本0.20.3取决于时间、pikaday和零剪贴板。有关更多信息,请参见dist/READEME.md。
https://stackoverflow.com/questions/28719633
复制相似问题