0
我需要窩我在JSON創建另一個數組的一個數組裏面,給它適當的格式化爲jQuery Datatables library.如何在JavaScript中嵌套另一個數組中的數組?
這裏是我當前的代碼:
$.ajax({
url: uMtbls,
dataType: 'json',
success: function(jMtbl) {
$.each(jMtbl, function(i, item) {
mAll = jMtbl[i];
mOwn = jMtbl[i].OrigOwner;
mPub = jMtbl[i].PublicationTblNm;
mTbl = jMtbl[i].TableId;
mMig = jMtbl[i].MigrationFreq;
mGTYPE = jMtbl[i].GTYPE;
exec();
});
oTable = $('#dtManaged').dataTable({
"bStateSave": true,
"bProcessing": true,
"bServerSide": true,
"aaData": jReform,
"aoColumns": [{
"sName": mOwn,
"sTitle": "Original Owner",
"sWidth": "10%"
}, {
"sName": mPub,
"sTitle": "Table Name"
}, {
"sName": mTbl,
"sTitle": "ID"
}, {
"sName": mMig,
"sTitle": "Migration Frequency"
}, {
"sName": mGTYPE,
"sTitle": "Oracle Gtype"
}],
"sPaginationType": "full_numbers",
"iDisplayLength": 25,
"aLengthMenu": [
[25, 50, 100, -1],
[25, 50, 100, "All"]
]
});
}
});
function exec() {
jBld = mOwn + "," + mPub + "," + mTbl + "," + mMig + "," + mGTYPE;
//console.debug("[" + mOwn + "," + mTbl + "]");
jReform = jBld.split(",");
console.debug(jReform);
}
輸出看起來像這樣(在捕獲console.debug):
["text","text","text","text","text"]
["text","text","text","text","text"]
樣品應該是:
{ "aaData": [
[ 10126, 10002253, 415 ]
]}
你爲什麼不解碼JSON到一個Javascript變量,然後操縱數據你想要嗎? – thatidiotguy
這就是我目前正在做的。我遇到了嵌套數組的問題,我在另一個數組中創建數組,以便將數據轉換爲所需的格式 – atlMapper
然後請僅顯示該代碼。 AJAX方面則無關緊要。只顯示必要的代碼。 – thatidiotguy