為了實現這樣的數據顯示出來三個序列
月份 鄭州
這樣
我寫了如下的函數實現這個功能
function CovertData(jsonData
var result = []
var fromFields = fromField
// 循環整個數組
for(var idx=
num = findIdx(result
if(num!=
curRecord = result[num];
}
else{
curRecord = {};
};
// 循環每個json對象中的字段
for(var key in jsonData[idx]){
// 處理轉換的數據內容
for(var i=
if(key == fromFields[i]){
curRecord[jsonData[idx][toField]+
break;
}
}
// 除數據內容外
if(key == idField){
curRecord[key] = jsonData[idx][key];
}
}
if(num==
result
}
}
return result;
}
function findIdx(jsonData
for(var idx =
if(jsonData[idx][columnName]==value)
return idx;
}
return
}
JsTestDriver的測試代碼如下
TestCase("Test json data row to column"
setUp:function(){
this
{yearmonth:
{yearmonth:
{yearmonth:
{yearmonth:
{yearmonth:
{yearmonth:
{yearmonth:
var fromField =
this
}
"test store has columns":function(){
var month
var month
var month
var month
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
assertEquals(
}
})
測試通過
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20611.html