【发布时间】:2019-12-12 13:37:54
【问题描述】:
来自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);
}
});
我想在这个函数之外的另一个函数中使用results。
我想在 highcharts 中使用这些 results 值。
有没有办法做到这一点?
【问题讨论】:
-
嗨@noob,请检查这个例子:jsfiddle.net/BlackLabel/9t3zeymv。经过小的更改后,您的代码似乎可以工作。
标签: javascript jquery json function highcharts