填充JSON全局数组 [英] fill global array with JSON
本文介绍了填充JSON全局数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很难codeD全局数组,看起来像
I have a hard coded global array that looks like
//var sectionL=[1,5,3,7,7,4,5,3,4,3,6,6,4,5,4,1];
相反,我想填补JSON请求全局数组
我试着用
Instead I would like to fill that global array from JSON request I tried with
var sectionL=[];
function fillsectionL(){
$.getJSON(baseURL+'&callback=?',function(data ){
var len= Object.keys(data['result']['sectionL']).length;
for(var i =0;i<len;i++){
sectionL[i]=data['result']['sectionL'];
}
});
}
我读到异步的,执行code前的输出将被解雇。有一个简单的方法来做到像
I read about asynchronous and that the output will be fired before the code is executed. Is there a simple way to do something like
sectionL=fillSection();
和已fillSection返回一个数组?
and have fillSection return an array?
推荐答案
我建议请点击此链接了解如何使用JavaScript数组。
I suggest to follow this link to learn how to work with javascript arrays.
http://www.w3schools.com/jsref/jsref_push.asp
这篇关于填充JSON全局数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文