gpt4 book ai didi

javascript - 从选定的 OrgChart 节点获取值 (Google orgchart)

转载 作者:太空宇宙 更新时间:2023-11-04 15:55:40 26 4
gpt4 key购买 nike

我正在尝试从 Google orgchart 的选定节点检索一个值,即姓名 Mike。目前,我在警报上显示了员工“v”的 ID,但没有显示姓名“f”。我尝试修改选择事件但没有成功。

有什么想法如何显示所选节点的特定值吗?

这是fiddle

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);
}
});
}

最佳答案

使用getFormattedValue方法...

    if (selectedItem) {
var selectedValue = data.getFormattedValue(selectedItem.row, 0);
console.log('The user selected ' + selectedValue);
}

v: -- 值 - getValue(rowIndex, columnIndex)

f: -- 格式化值 - getFormattedValue(rowIndex, columnIndex)

<小时/>

其他方法 --> DataTable methods

关于javascript - 从选定的 OrgChart 节点获取值 (Google orgchart),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42724267/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com