我正在使用 Google Charts 获得选择事件的未定义列索引。这里有类似的问题,这里和这里我看过,但没有解决我的问题。我的目标是能够确定用户何时单击“[x]”以从表中删除相应的行。谢谢你。
var data = new google.visualization.DataTable();
data.addColumn('string', 'Site');
data.addColumn('number', 'Logins');
data.addColumn('string', '');
data.addRows([['ABC', 123, '[ x ]']]);
function drawTable() {
// Create and draw the visualization.
visualization = new google.visualization.Table(document.getElementById('table_div'));
visualization.draw(data, null);
google.visualization.events.addListener(visualization, 'select', selectHandler);
}
function selectHandler() {
var selectedItem = visualization.getSelection()[0];
console.log(selectedItem); // output: Object {row: 0}
if (selectedItem == undefined)
return false;
console.log(selectedItem.column); // output: undefined
var value = data.getValue(selectedItem.row, selectedItem.column);
console.log(value); // output: Uncaught Error: Invalid column index undefined. Should be an integer in the range [0-3].
}