/ Published in: JavaScript
Outputs the contents of a javascript object to a div called #output. Can be useful in some circumstances
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function outputData() { var ob = propertyBox.getObject(); $("#output").html(""); var outputText = "<ul>"; outputText += _outputRecursive(ob, ""); outputText += "</ul>"; $("#output").html(outputText); } function _outputRecursive(ob, text) { var text2 = text; for (var prop in ob) { if (!ob.hasOwnProperty(prop)) { continue; } text2 += "<li>"; var val = ob[prop]; if (val instanceof Object && !(val instanceof Array)) { text2 += "<b>" + prop + "</b>"; text2 += "<ul>" + _outputRecursive(val, "") + "</ul>"; } else { if (val instanceof Array) { val = $.toJSON(val); // convert to string } text2 += "<b>" + prop + "</b>: " + val; } text2 += "</li>"; } return text2; }