Meteor, where to put d3 code?

后端 未结 1 690
天涯浪人
天涯浪人 2020-12-18 13:35

I use meteor, iron-router, and d3. d3 is used to reactively display a pie chart based on the data, which I calculate in the data function of iron-router. So, I want to the d

相关标签:
1条回答
  • 2020-12-18 14:26

    You should use the onRendered callback with a template autorun. Out of the box that doesn't work with 1.0, however there's a trick - you can get the autorun to rerun after a context change by using Template.currentData like this:

    Template.myPictures.onRendered(function () {
      this.autorun(function () {
        var data = Template.currentData();
        // use data with d3 here
      });
    });
    

    For more details, see the end of this issue.

    0 讨论(0)
提交回复
热议问题