根据D3 JS漏斗中的最新文档,我有文档中提到的点击事件回调。但当我无法使用this.try((.从角度组件内部访问函数时
这里是实现,不知道如何实现它。
JS代码
const options = {
chart: { bottomPinch: 1, animate: 200, height: 300 },
block: {
// dynamicHeight: true,
// dynamicSlope: true,
highlight: true,
},
events: {
click: {
block(d) {
console.log(d.label.raw);
this.try(d.label.raw);
},
},
},
tooltip: { enabled: true, }
};
const chart = new D3Funnel('#d3Funnel');
chart.draw(data, options);
})
HTML
<div id="d3Funnel"></div>
它给出错误
ERROR TypeError: this.try is not a function
at SVGPathElement.block
我不知道如何解决这个问题。
图书馆参考资料https://github.com/jakezatecky/d3-funnel
block(d) { ... }
只是block: function(d) { ... },
的简写,它不会在词法上绑定它。
如果您将事件替换为箭头函数,例如block: (d) => { ... }
,那么您的代码将能够按照您的意愿解决此问题。