如何在 handsontable 中的同一个钩子中绑定多个事件?
How to bind multiple events in same hooks in handsontable?
描述
如何将多个事件绑定到同一个钩子中?
假设我有一个名为 updateDataDump
的函数,现在每当这些事件发生时 afterChange
、afterColumnMove
、afterRemoveRow
或 afterRemoveCol
。我希望执行该功能。
Handsontable.hooks.add('afterChange', () => {
updateDataDump();
});
Handsontable.hooks.add('afterColumnMove', () => {
updateDataDump();
});
Handsontable.hooks.add('afterRemoveRow', () => {
updateDataDump();
});
Handsontable.hooks.add('afterRemoveCol', () => {
updateDataDump();
});
有什么方法可以将所有功能合二为一吗?
您的环境
- 掌上电脑版本:版本:0.32.0
- 浏览器名称和版本:Google Chrome 57.0.2987.110(64 位)
- 操作系统:Ubuntu14.04
遗憾的是,没有内置选项可以同时向几个挂钩添加逻辑。
有了你可以选择的解决方案也叫updateSettings
hot.updateSettings({
afterChange: function(){
updateDataDump()
},
afterColumnMove: function(){
updateDataDump()
},
afterRemoveRow: function(){
updateDataDump()
},
afterRemoveCol: function(){
updateDataDump()
},
});
function updateDataDump(){
}
或者只使用挂钩名称,因为 addHook
方法使用挂钩的字符串表示形式。
var hooks = ['afterChange', 'afterColumnMove', 'afterRemoveRow', 'afterRemoveCol'];
for(var i = 0; i < hooks.length; i++){
hot.addHook(hooks[i], updateDataDump);
}
function updateDataDump(){
}
描述
如何将多个事件绑定到同一个钩子中?
假设我有一个名为 updateDataDump
的函数,现在每当这些事件发生时 afterChange
、afterColumnMove
、afterRemoveRow
或 afterRemoveCol
。我希望执行该功能。
Handsontable.hooks.add('afterChange', () => {
updateDataDump();
});
Handsontable.hooks.add('afterColumnMove', () => {
updateDataDump();
});
Handsontable.hooks.add('afterRemoveRow', () => {
updateDataDump();
});
Handsontable.hooks.add('afterRemoveCol', () => {
updateDataDump();
});
有什么方法可以将所有功能合二为一吗?
您的环境
- 掌上电脑版本:版本:0.32.0
- 浏览器名称和版本:Google Chrome 57.0.2987.110(64 位)
- 操作系统:Ubuntu14.04
遗憾的是,没有内置选项可以同时向几个挂钩添加逻辑。
有了你可以选择的解决方案也叫updateSettings
hot.updateSettings({
afterChange: function(){
updateDataDump()
},
afterColumnMove: function(){
updateDataDump()
},
afterRemoveRow: function(){
updateDataDump()
},
afterRemoveCol: function(){
updateDataDump()
},
});
function updateDataDump(){
}
或者只使用挂钩名称,因为 addHook
方法使用挂钩的字符串表示形式。
var hooks = ['afterChange', 'afterColumnMove', 'afterRemoveRow', 'afterRemoveCol'];
for(var i = 0; i < hooks.length; i++){
hot.addHook(hooks[i], updateDataDump);
}
function updateDataDump(){
}