相关疑难解决方法(0)

如何将D3 JavaScript中的'this'翻译成TypeScript?

我知道JavaScript中的'this'与TypeScript中的含义不同,根据TypeScript中的这篇文章'this'.我在JavaScript中使用以下代码用于在所选节点上创建较粗的笔划,并为所有其他节点提供较小的笔划.

node.on('click', function (d) {
   d3.selectAll('circle').attr('stroke-width', 1.5);
   d3.select(this).select('circle').attr('stroke-width', 5);
})
Run Code Online (Sandbox Code Playgroud)

在TypeScript我有

this.node.on('click', (d:any) => {
   this.node.selectAll('circle').attr('stroke-width', 1.5);
   [this is where I need help].select('circle').attr('stroke-width', 5);
}
Run Code Online (Sandbox Code Playgroud)

javascript lexical-scope d3.js typescript arrow-functions

5
推荐指数
2
解决办法
1267
查看次数