简体   繁体   中英

Polymer: Get element by id within a function

I have a polymer element that contains a line graph using a charting library that has a built in onclick function when I click one of the data points on the chart. I set this onclick function to call a function named generatePie().

Within generatePie(), I want to modify the local DOM by grabbing an element by ID in the typical polymer convention this.$.elementid. However, "this" now refers to the function generatePie(). Is there a workaround to this?

Sort of a hack but...created a global variable. Set an onclick function for the whole div that the chart is rendered in. Whenever any part of the chart was clicked, the onclick function will update the global variable to to one I want.

callback = function generatePie() {...}.bind(this)在当前上下文是自定义组件的情况下,从而使generatePie内部的“ this”成为具有本地DOM的组件吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM