js动态变量问题
var lastchartdata = [];
var
lv = targetArray[i];
for(var j=0;j<json.length;j++){
if(j==0){
lastchartdata.push({
lv:eval("json[j]." + targetArray[i])});
}else{}
各位大侠:我想问下如何把下面那个lv是上面定义的lv的值
取值的时候这样alert(lastchartdata[0].
定义的lv的值);
------解决方案--------------------
抱歉,函数后面少了两句……
[code=javascript]
function changeData(totalJsonArray, targetArray) {
var lastchartdata=[];
for(var i = 0, il = totalJsonArray.length; i < il; i++){
var json = Ext.util.JSON.decode(totalJsonArray[i]);
var lv = targetArray[i];
var temp = {};
for(var j = 0, jl = json.length, jo; j < jl; j++){
jo = json[i];
for(var p in jo) if(jo.hasOwnProperty(p)){
if(temp[p]) {
temp[p] = [temp[p]];
[p].push(jo[p])
}
else temp[p] = jo[p];
}
}
lastchartdata.push(temp);
return lastchartdata