【发布时间】:2014-11-20 05:53:43
【问题描述】:
我尝试从 ajax json 推入我的数组循环数据,但 $.getJSON("/admin/reports/stats/1", function(datas) {}); 之外的数据变量为空
var data = [];
$.getJSON("/admin/reports/stats/1", function(datas) {
$(datas).each(function(index, value){
obj={};
obj['label']= value.publisher_name;
obj['data']= value.sale;
data.push(obj);
});
console.log(data); //here I see the content of array
});
console.log(data); //here is empty
【问题讨论】:
-
你会找到答案和解释here。
-
使用 .done() 并在那里对您的数据执行操作。
标签: jquery arrays variables each