您好,我已经将数据从 google 电子表格捕获到一个像这样的新数组
$.getJSON("https://spreadsheets.google.com/feeds/list/1IoNqeReOPKNFrYMlK2rnJVuMaLeAgnZneLbKYSQ7bs4/od6/public/values?alt=json", function(data) {
//$.getJSON("http://cors.io/spreadsheets.google.com/feeds/list/1IoNqeReOPKNFrYMlK2rnJVuMaLeAgnZneLbKYSQ7bs4/od6/public/values?alt=json", function(data) {
var len = data.feed.entry.length;
for (var i=0; i<len; i++) {
//first row "title" column
resultData[i]=new Array(9);
resultData[i][1]=data.feed.entry[i].gsx$constituency.$t;
resultData[i][2]=data.feed.entry[i].gsx$winner2010.$t;
resultData[i][3]=data.feed.entry[i].gsx$winningparty.$t;
resultData[i][4]=data.feed.entry[i].gsx$candidatename1.$t;
resultData[i][5]=data.feed.entry[i].gsx$party1.$t;
resultData[i][6]=data.feed.entry[i].gsx$candidatename2.$t;
resultData[i][7]=data.feed.entry[i].gsx$party2.$t;
resultData[i][8]=data.feed.entry[i].gsx$candidatename3.$t;
resultData[i][9]=data.feed.entry[i].gsx$party3.$t;
}
});
如何将上面的内容重写为如下所示的文字数组
var colors = [gsx$constituency, gsx$winner2010];
我仍在学习编写代码,因此将不胜感激
最佳答案
我认为你应该像下面这样更新你的代码:
$.getJSON("https://spreadsheets.google.com/feeds/list/1IoNqeReOPKNFrYMlK2rnJVuMaLeAgnZneLbKYSQ7bs4/od6/public/values?alt=json", function(data) {
data.feed.entry.forEach(function(singleEntry) {
var resultData = [];
resultData.push(singleEntry);
})
});
现在您可以获得像resultData[index].gsx$constituency 这样的数据。
关于javascript - 如何在 Javascript 中从新数组方法重写为文字数组方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33362606/