1

好的,所以有一个名为ChartistJS的图表库。我在其中使用了一个名为Axistitle 插件的插件来显示axisTitle。我创建了一个plunker来突出这个问题。现在的问题是,当我打开下拉列表时,我想根据我选择的选项查看不同的轴标题。听起来很简单。

现在,如果您转到chartist-plugin-axistitle.js第 44 和 49 行的源代码,您会发现两个console.logs(options). 现在打开开发者控制台,清除控制台并从下拉列表中选择选项距离。您将在第 44 行和第 49 行看到两个 console.log()。现在查看第axisY.axistitle44 行和axisY.axistitle第 49 行的变量。看起来不同??一个必须Distance(km)在第 44 行,这是预期值,第 49 行将是Unit。为什么?上一行的值变成了Distance(km),还是Unit?它正在执行和打印,但为什么函数没有采用更新的值?我闻到它与关闭有关?我将如何解决这个问题?如何获得其中选项的更新值?

帮助表示赞赏。谢谢

编辑

因为我应该在这里给出一些简约的代码。

Chartist.plugins.ctAxisTitle = function(options) {

    options = Chartist.extend({}, defaultOptions, options);
    console.log(options); // I get updated values
    console.log("I am printed everytime too. Because I am supposed too.");
    return function ctAxisTitle(chart) {
        console.log("I will get printed first time but not subsequent times. I don't know why?");
        chart.on('created', function(data) {
            console.log("I am printed every time as chart is re-rendered/created every time it is updated");
console.log(options); //Should be closure of above value. But I won't take updated options value. I'll stick with the one I was initialized with. Coz I am stupid.
        });
    };
};
4

0 回答 0