下面的函数应返回具有以下结构的对象数组:
TopicFrequency = {
name: "Chemistry", //This is dependent on topic
data: [1,2,3,4,5,6,7,8,9,10,11,12] //This would be real data
};
所以当我这样做时:
myData = this.getChartData("line");
它应该返回两个对象:
{name : "Chemistry", data : [1,2,3,4,51,12,0,0, 2,1,41, 31]}
{name : "Math", data : [0,0,41,4,51,12,0,0, 2,1,41, 90]}
所以当我做console.log(myData);
它是完美的时候,就这样回复。
然而,当我执行console.log(myData[0].data)
时,它返回所有0,而不是值。我不确定这个问题是什么,我的问题很简单,这个问题是什么?
这是完整的功能。 Somethings是硬编码的,其他变量(着名的服务器和queryContent)被删除。这些部分工作正常,只有当操纵/检索返回的数组的值时才会遇到问题。注意这是异步的。所以不确定这是否也是问题的一部分。
getChartData: function (chartType) {
var TopicsFrequencyArray = new Array();
timePairs = this.newIntervalSet("Month");
topicList = new Array("Chemistry", "Math");//Hard coded for now
var queryCopy = {
//sensitive information
};
for (i = 0; i < topicList.length; i++) {
var TopicFrequency = {
name: null,
data: this.newFilledArray(12, 0)
};
j = 0;
TopicFrequency.name = topicList[i];
while (j < timePairs.length) {
queryCopy.filter = TopicFrequency.name;
//additional queryCopy parameter changes made here
var request = esri.request({ url: server, content: queryCopy, handleAs: "json", load: sucess, error: fail });
j = j + 1;
function sucess(response, io) {
var topicCountData = 0;
query = esri.urlToObject(io.url);
var dateString = query.query.fromDate.replace("%", " ");
dateString = dateString.replace(/-/g, "/");
dateString = dateString.split(".");
date = new Date(dateString[0]);
dojo.forEach(response.features, function (feature) {
if (feature.properties.count > 0) {
topicCountData = feature.properties.count;
}
TopicFrequency.data[date.getMonth()] = topicCountData;
});
}
function fail(error) {
j = j + 1;
alert("There was an unspecified error with this request");
console.log(error);
}
}
TopicsFrequencyArray.push(TopicFrequency);
}
},