我正在阅读ajax调用并将值和技巧插入数组
$.ajax({
async: false, //thats the trick
url: '/Test/Test.jsp',
dataType: 'json',
success: function(response){
$.each(response, function(index, element) {
newdata.push(newdata.length, parseInt(element[1]));
newticks.push(newticks.length, element[0]);
});
data = response;
}
});
此格式的新数据数据
0,20,1,60,2,10,3,67,4,76,5,10
但是flotr期待[[0, 20],[ 1, 60],[ 2, 10],[ 3, 67],[4,76]]
任何解决方案?感谢
答案 0 :(得分:1)
如果回复是字符串:"4,32,45,3,56,3,67..."
你可以写:
$.each(response.split(','), function (index, element){
newdata.push(new Array(newdata.length, parseInt(element[1])));
newticks.push(new Array(newticks.length, parseInt(element[0])));
});
或:
$.each(response.split(','), function (index, element){
var temp = null;
newdata.push(temp = [newdata.length, parseInt(element[1])]);
newticks.push(temp = [newticks.length, parseInt(element[0])]);
});
我认为第一个变体乍一看更清楚,但两者都是等价的。