使用此代码,我可以使用值填充数据网格。每个项目都是一行。
gridDataVK4000 = {
items : [{
"Datum" : GridDate[0],
"VERSENDET_PDF" : values[0][0],
"FAKTUREN_POSTBILLING" : values[1][0],
"VERSENDET_XML" : values[2][0],
"VERARBEITET_PDF_TCO" : values[3][0],
"VERARBEITET_XML_TCO" : values[4][0]
}, {
"Datum" : GridDate[1],
"VERSENDET_PDF" : values[0][1],
"FAKTUREN_POSTBILLING" : values[1][1],
"VERSENDET_XML" : values[2][1],
"VERARBEITET_PDF_TCO" : values[3][1],
"VERARBEITET_XML_TCO" : values[4][1]
}, {
"Datum" : GridDate[2],
"VERSENDET_PDF" : values[0][2],
"FAKTUREN_POSTBILLING" : values[1][2],
"VERSENDET_XML" : values[2][2],
"VERARBEITET_PDF_TCO" : values[3][2],
"VERARBEITET_XML_TCO" : values[4][2]
}....
现在我想把它写得更短。到目前为止这是我的代码。但我不知道如何在正确的结构中获取值:
var gridDataVK40001 = [];
var key,
i;
for (i = 0; i < 14; i++) {
key = i + "";
gridDataVK40001.push({
"Datum" : GridDate[i],
"Fakturen_gesamt" : values[0][i],
"T1" : values[1][i],
"T2" : values[2][i],
"versendete PDF" : values[3][i],
"VERARBEITETE PDFs TSBS" : values[4][i],
"VERARBEITETE IDOCs TSBS" : values[5][i]
});
}
实际结构:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
目标结构:
Object {items: Array[15]}
任何sugestions?
答案 0 :(得分:0)
您的gridDataVK40001
变量是Array
([]
)。您需要Object
({}
)items
数组属性:
var gridDataVK40001 = {items: []};
var key,
i;
for (i = 0; i < 14; i++) {
key = i + "";
// we now push to the item property
gridDataVK40001.items.push({
"Datum": GridDate[i],
"Fakturen_gesamt": values[0][i],
"T1": values[1][i],
"T2": values[2][i],
"versendete PDF": values[3][i],
"VERARBEITETE PDFs TSBS": values[4][i],
"VERARBEITETE IDOCs TSBS": values[5][i]
});
}