andrew4582

dumpDictionary and dumpList debug helpers

Feb 17th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dumpDictionary(data, keyval, valueval) {
  2.     /// <summary>
  3.     ///     Renders a json dictionary and/or key value array into a ul list
  4.     /// </summary>
  5.     /// <param name="data" type="PlainObject">
  6.     ///     Object that contains the array of values to dump
  7.     /// </param>
  8.     /// <param name="keyval" type="PlainObject">
  9.     ///     Object that contains a function or the an item's property name
  10.     /// </param>
  11.     /// <param name="valueval" type="PlainObject">
  12.     ///     Object that contains a function or the an item's property name
  13.     /// </param>
  14.     /// <returns type="string" >
  15.     /// The html list of provieded json data
  16.     /// </returns>
  17.     var items = [];
  18.     items.push("<ul>");
  19.    
  20.     for (var i = 0; i < data.length; i++) {
  21.         var item = data[i];
  22.         var key,value;
  23.         if (keyval != null) {
  24.             if (typeof (keyval) === "function")
  25.                 key = keyval(item, i);
  26.             else
  27.                 key = item[keyval];
  28.         }
  29.         if (valueval != null) {
  30.             if (typeof (valueval) === "function")
  31.                 value = valueval(item,i);
  32.             else
  33.                 value = item[valueval];
  34.         }
  35.         items.push('<li>' + key + " = " +  value + '</li>');
  36.     }
  37.     items.push("</ul>");
  38.     var html = items.join('');
  39.     return html;
  40. }
  41.  
  42.  
  43. function dumpList(data, valueval) {
  44.     /// <summary>
  45.     ///     Renders a json value array into a ul list
  46.     /// </summary>
  47.     /// <param name="data" type="PlainObject">
  48.     ///     Object that contains the array of values to dump
  49.     /// </param>
  50.     /// <param name="valueval" type="PlainObject">
  51.     ///     Object that contains a function or the an item's property name
  52.     /// </param>
  53.     /// <returns type="string" >
  54.     /// The html list of provieded json data
  55.     /// </returns>
  56.     var items = [];
  57.     items.push("<ul>");
  58.     for (var i = 0; i < data.length; i++) {
  59.         var item = data[i];
  60.         var value;
  61.         if (valueval != null) {
  62.             if (typeof (valueval) === "function")
  63.                 value = valueval(item,i);
  64.             else
  65.                 value = item[valueval];
  66.         }
  67.         items.push('<li>' + value + '</li>');
  68.     }
  69.     items.push("</ul>");
  70.     var html = items.join('');
  71.     return html;
  72. }
Add Comment
Please, Sign In to add comment