【发布时间】:2015-03-31 09:24:15
【问题描述】:
我尝试通过使用禁用删除键
stopImmediatePropagation() 函数,就像它在文档中描述的那样,但它不会阻止删除键的默认行为。
【问题讨论】:
标签: handsontable
我尝试通过使用禁用删除键
stopImmediatePropagation() 函数,就像它在文档中描述的那样,但它不会阻止删除键的默认行为。
【问题讨论】:
标签: handsontable
我遇到了同样的问题,文档有误。检查this issue。 您需要启用立即传播:
Handsontable 0.16:
beforeKeyDown: function (event) {
if (e.keyCode === 46) {
Handsontable.Dom.enableImmediatePropagation(event);
event.stopImmediatePropagation();
}
}
注意,在 Handsontable 0.17 中,语法已更改为:
beforeKeyDown: function (event) {
if (e.keyCode === 46) {
Handsontable.Dom.stopImmediatePropagation(event);
}
}
以下是基于您的小提琴的工作示例:
$(document).ready(function()
{
var data = [
['Nissan', 2009, 'black', 'black'],
['Nissan', 2006, 'blue', 'blue'],
['Chrysler', 2004, 'yellow', 'black'],
['Volvo', 2012, 'yellow', 'gray']
],
container = document.getElementById("example1"),
lastChange = null,
hot;
hot = new Handsontable(container, {
data: data,
colHeaders: true,
rowHeaders: true,
minSpareRows: 1,
beforeChange: function (changes, source) {
lastChange = changes;
}
});
hot.updateSettings({
beforeKeyDown: function (e) {
if (e.keyCode === 46) {
Handsontable.Dom.enableImmediatePropagation(e);
e.stopImmediatePropagation();
}
}
});
});
body { background: white; margin: 20px; }
h2 { margin: 20px 0; }
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://docs.handsontable.com/0.16.0/bower_components/handsontable/dist/handsontable.full.js"></script>
<link rel="stylesheet" media="screen" href="http://handsontable.com/dist/handsontable.full.css">
<link rel="stylesheet" media="screen" href="http://handsontable.com/demo/css/samples.css?20140331">
<link rel="stylesheet" media="screen" href="http://handsontable.com/demo/css/samples.css?20140331">
<link rel="stylesheet" media="screen" href="http://handsontable.com/demo/css/samples.css?20140331">
<h2>beforeKeyDown callback</h2>
<p>The following demo uses <code>beforeKeyDown</code> callback to modify some key bindings:</p>
<div id="example1" class="handsontable"></div>
【讨论】: