angular - 如何在highcharts树图点击事件中调用外部方法?
问题描述
我正在使用 highcharts 树图。我想在树形图单击事件中调用其他方法(this.callOutsidemethod )。但是我的代码不起作用,并在下面添加了我的代码。我想知道如何在打字稿中的树形图单击函数中调用外部方法。
export class AppComponent implements OnInit {
name = `Angular! v${VERSION.full}`;
@ViewChild("container", { read: ElementRef }) container: ElementRef;
constructor() {
}
ngOnInit() {
Highcharts.chart(this.container.nativeElement, {
colorAxis: {
minColor: '#FFFFFF',
maxColor: Highcharts.getOptions().colors[0]
},
plotOptions: {
series: {
cursor: 'pointer',
events: {
click: function (event) {
this.callOutsidemethod();
}
}
}
},
series: [{
type: 'treemap',
//layoutAlgorithm: 'squarified',
data: [{
name: 'A',
value: 6,
colorValue: 1
}, {
name: 'B',
value: 6,
colorValue: 2
}, {
name: 'C',
value: 4,
colorValue: 3
}, {
name: 'D',
value: 3,
colorValue: 4
}, {
name: 'E',
value: 2,
colorValue: 5
}, {
name: 'F',
value: 2,
colorValue: 6
}, {
name: 'G',
value: 1,
colorValue: 7
}]
}],
title: {
text: 'Highcharts Treemap'
}
})
}
callOutsidemethod(){
alert("hii")
}
}```
解决方案
this
您可以使用箭头函数表示法来使用关键字来引用成员变量。尝试以下
events: {
click: (event) => {
// do something
this.callOutsidemethod();
}
}
推荐阅读
- javascript - 浏览器一次只能下载 10 张图片(JS)
- r - R 相当于在 Matlab 中置换数组维度 permute(A, dimorder)
- mongodb - 如何避免 MongoDB 聚合中的 $unwind 和 $group
- api - Blazor Server 失去与移动浏览器的连接
- customization - Serilog,如何以编程方式将 FileSink 参数化为在自定义接收器中的日期更改和文件大小处滚动文件名
- google-bigquery - 格式化/美化 bigquery 代码(如程序)
- windows - 如何在windows中安装GStreamer的插件
- ruby - 我从 rubocop 收到 ABC 错误的错误,我该如何删除它
- python - 如何使用 Telethon 静音电报用户的通知?
- javascript - 如何在reactjs中映射对象的顺序编号属性