Return to Snippet

Revision: 30656
at August 18, 2010 23:39 by BenClayton


Initial Code
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;
    }

Initial URL

                                

Initial Description
Outputs the contents of a javascript object to a div called #output. Can be useful in some circumstances

Initial Title
Output javascript object to div recursively.

Initial Tags

                                

Initial Language
JavaScript