关于Use variable from one forEach Method in another的后续行动。如何在函数外部使用在 then()
中获得的值?
var first, second;
$.when(
$.getJSON(json1, result => first = result);
$.getJSON(json2, result => second = result);
).then(function() {
if (first && second) {
let results = first.map((item, index) => item.x / second[index].v);
}
});
我想在另一个函数中使用此函数之外的结果
。
我想在 highcharts 中使用这些结果
值。
有办法做到这一点吗?
最佳答案
在回调函数中初始化Highchart.js。
var first, second;
$.when(
$.getJSON(json1, result => first = result);
$.getJSON(json2, result => second = result);
).then(function() {
if (first && second) {
let results = first.map((item, index) => item.x / second[index].v);
Highcharts.chart('container', {
...
});
}
});
关于javascript - 在函数外部使用 $when...then() 内部的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57351660/