我试图从Google orgchart的选定节点中检索一个值,即名称Mike。目前,我在通知中显示了员工"v“的ID,但没有显示"f”的名称。我试图修改select事件,但没有成功。
如何显示选定节点的特定值,有什么想法吗?
这是小提琴
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Rank');
data.addColumn('string', 'ToolTip');
// For each orgchart box, provide the name, manager, and tooltip to show.
data.addRows([
[{ "v": '1', f: 'Mike<div style="color:red; font-style:italic">President</div>' }, '', 'The President'],
[{ "v": '2', f: 'Jim<div style="color:red; font-style:italic">vice</div>' }, '1', 'VICE'],
[{ "v": '3', f: 'Three<div style="color:red; font-style:italic">vice</div>' }, '1', 'VICE'],
[{ "v": '4', f: 'Four<div style="color:red; font-style:italic">vice</div>' }, '3', 'VICE'],
[{ "v": '5', f: 'Five<div style="color:red; font-style:italic">vice</div>' }, '3', 'VICE']
]);
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, { allowHtml: true });
// When the orgchart is selected
google.visualization.events.addListener(chart, 'select', function () {
// alert('sel');
this.blur;
var selectedItem = chart.getSelection()[0];
if (selectedItem) {
var selectedValue = data.getValue(selectedItem.row, 0);
console.log('The user selected ' + selectedValue);
}
});
}发布于 2017-03-10 17:28:50
使用getFormattedValue方法..。
if (selectedItem) {
var selectedValue = data.getFormattedValue(selectedItem.row, 0);
console.log('The user selected ' + selectedValue);
}v: - value - getValue(rowIndex, columnIndex)
f: --格式化值- getFormattedValue(rowIndex, columnIndex)
其他方法-> DataTable方法
https://stackoverflow.com/questions/42724267
复制相似问题