Ide dasarnya adalah apa yang dijelaskan oleh @Gates VP. Saya menggunakan underscore.js untuk beralih melalui array/objek.
function formatLog(obj){
var log = "";
_.each(obj, function(val, key){
if(typeof(val) === "object" || typeof(val) === "array"){
// if we have a new list
log += "<ul>";
log += formatLog(val);
log += "</ul>";
}
else{
// if we are at an endpoint
log += "<li>";
log += (key + ": " + val);
log += "</li>";
}
});
return log;
}
Jika Anda memanggil formatLog()
pada contoh data yang Anda berikan kembali
- ServerAlias:GBIZ-WEB
- urltoken:CFID=10989&CFTOKEN=f07fe950-53926E3B-F33A-093D-3FCEFB&jsessionid=84303d29a229d1
- id sesi:84197a667053f63433672873j377e7d379101
- UUID:53934LBB-DB8F-79T6-C03937JD84HB864A338
- Templat:/home/vagrant/dev/websites/g-bis/code/webroot/page/home/home.cfm, baris 3
- Konten yang Dihasilkan:
- Surat:
- Pesan:Tag tidak dikenal:cfincflude.
- namatag:cfincflude
- RAW_TRACE:di cfhome2ecfm1296628853.runPage(/home/vagrant/dev/websites/nig-bis/code/webroot/page/home/home.cfm:3)
- ID:CFINCLUDE
- TEMPLATE:/home/vagrant/dev/websites/nig-bis/code/webroot/page/home/home.cfm
- GARIS:3
- JENIS:CFML
- KOLOM:0
- RAW_TRACE:di cfdisplay2ecfm1093821753.runPage(/home/vagrant/dev/websites/nig-bis/code/webroot/page/display.cfm:6)
- ID:CFINCLUDE
- TEMPLATE:/home/vagrant/dev/websites/nig-bis/code/webroot/page/display.cfm
- LINE:6
- JENIS:CFML
- KOLOM:0
Bagaimana memformatnya terserah Anda.