2011-12-13 71 views
0

我有从一个php文件进来的JSON响应,JSON响应看起来如下结果:如何将json响应复制到extjs中的数组中?

[ 
    { 
     "header": "Client ID", 
     "dataindex": "clientID" 
    }, 
    { 
     "header": "Client Name", 
     "dataindex": "clientName" 
    }, 
    { 
     "header": "Progress Bar", 
     "dataindex": "progressBar" 
    } 
] 

现在我想这个数据复制到以下述方式的阵列 变种allColumns = [];

//loop through the json response 
var singleColumn = []; 
singleColumn['header'] = Client ID from the json response whose key is header 
singleColumn[dataindex'] = clientID from the json response whose key is header. 

请注意:我需要做的是extjs3。

回答

1

如果我正确地得到了你,你将JSON作为一个字符串从一个字符串格式的ajax调用发送到你的PHP处理程序,并且你想将它转换成一个coloumn对象的Javascript数组。

,你可以做这样的:

var allColumns = Ext.decode(YOUR PHP JSON FORMATTED RESULT); 

这将允许您遍历结果在内存设置为JavaScript对象的数组是这样的:

for(var i=0 ; i < allColumns.length; i++){ 
    allColumns[i].header ... 
    allColumns[i].dataindex ... 
} 

我希望我有你对...

相关问题