added method
This commit is contained in:
parent
2e0f09fc5a
commit
a3aacc6412
|
@ -354,4 +354,54 @@ public class GeoPortalDataEntryApp implements EntryPoint {
|
|||
});
|
||||
}
|
||||
|
||||
public static native String jsonToHTML(String jsonTxt)/*-{
|
||||
try
|
||||
{
|
||||
var jsonObj = JSON.parse(jsonTxt);
|
||||
|
||||
if(jsonObj.length==undefined)
|
||||
jsonObj = [jsonObj]
|
||||
//console.log(jsonObj.length)
|
||||
|
||||
// EXTRACT VALUE FOR HTML HEADER.
|
||||
var col = [];
|
||||
for (var i = 0; i < jsonObj.length; i++) {
|
||||
for (var key in jsonObj[i]) {
|
||||
//console.log('key json' +key)
|
||||
if (col.indexOf(key) === -1) {
|
||||
col.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CREATE DYNAMIC TABLE.
|
||||
var table = document.createElement("table");
|
||||
try{
|
||||
table.classList.add("my-html-table");
|
||||
|
||||
}catch(e){
|
||||
console.log('invalid css add', e);
|
||||
}
|
||||
|
||||
// ADD JSON DATA TO THE TABLE AS ROWS.
|
||||
for (var i = 0; i < col.length; i++) {
|
||||
tr = table.insertRow(-1);
|
||||
var firstCell = tr.insertCell(-1);
|
||||
//firstCell.style.cssText="font-weight: bold; text-align: center; vertical-align: middle;";
|
||||
firstCell.innerHTML = col[i];
|
||||
for (var j = 0; j < jsonObj.length; j++) {
|
||||
var tabCell = tr.insertCell(-1);
|
||||
var theValue = jsonObj[j][col[i]];
|
||||
tabCell.innerHTML = theValue;
|
||||
}
|
||||
}
|
||||
|
||||
return table;
|
||||
}
|
||||
catch(e){
|
||||
console.log('invalid json', e);
|
||||
}
|
||||
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue