Gracias, Wikipedia.
ShareCode
Permalink: http://www.treeweb.es/u/974/ 01/02/2011

ShareCode

1 var MongoString = function() {2  var that = this;3  4  this.dom = document.createElement('div');5  this.dom.setAttribute('contentEditable', true);6  this.dom.setAttribute('component', 'MongoString');7  8  this.setData = function(data) {9  that.dom.innerHTML = data; // TODO: change this by contentText10  };11  12 };13 14 var MongoNumber = function() {15  var that = this;16  17  this.dom = document.createElement('div');18  this.dom.setAttribute('contentEditable', true);19  this.dom.setAttribute('component', 'MongoNumber');20  21  this.dom.addEventListener('keyup', function(){22  console.log(""+parseFloat(this.innerHTML));23  }, true);24  25  this.setData = function(data) {26  that.dom.innerHTML = data; // TODO: change this by contentText27  };28  29 };30 31 var MongoKeyValue = function() {32  var that = this;33  34  var key = '';35  36  this.dom = document.createElement('div');37  this.dom.setAttribute('component', 'MongoKeyValue');38  39  this.key = document.createElement('div');40  this.key.classList.add('key');41  this.dom.appendChild(this.key);42  43  this.value = document.createElement('div');44  this.value.classList.add('value');45  this.dom.appendChild(this.value);46  47  this.setKey = function(k) {48  key = k;49  that.key.innerHTML = k; // TODO user contentText (check spelling)50  };51 };52 53 var MongoDocument = function() {54  55  var that = this;56  57  this.items = null;58  59  this.dom = document.createElement('div');60  this.dom.setAttribute('component', 'MongoDocument');61  62  this.setData = function(data) {63  // TODO: clear this64  for (i in data) { // TODO: change i by key65  var type = typeof data[i];66  if ('_id' == i) {67  type = 'id';68  } else if ('object' == type && data[i] instanceof Array) {69  type = 'array';70  } else if ('object' == type && null === data[i]) {71  type = 'null';72  }73  74  var mkv = new MongoKeyValue();75  mkv.setKey(i);76  77  switch (type) {78  case 'id':79  console.log('uno');80  break;81  case 'undefined':82  console.log('dos');83  break;84  case 'null':85  console.log('tres');86  break;87  case 'boolean':88  console.log('cuatro');89  break;90  case 'string':91  var ms = new MongoString();92  ms.setData(data[i]);93  mkv.value.appendChild(ms.dom);94  break;95  case 'number':96  var mn = new MongoNumber();97  mn.setData(data[i]);98  mkv.value.appendChild(mn.dom);99  break;100  case 'object':101  console.log('siete');102  break;103  case 'array':104  console.log('ocho');105  break;106  }107  108  that.dom.appendChild(mkv.dom);109  110  //that.dom.innerHTML += i + ':' + data[i] + '(' + type + ')<br>';111  }112  };113  114 };115 116 var MongoCollection = function() {117  118  var that = this;119  120  this.documents = [];121  122  this.dom = document.createElement('div');123  this.dom.setAttribute('component', 'MongoCollection');124  125  this.SetData = function(data) {126  // TODO: destroy all items127  for (i in data) {128  var d = data[i];129  var item = new MongoDocument();130  item.setData(d);131  that.dom.appendChild(item.dom);132  }133  };134  135 };


Este ShareCode tiene versiones:
  1. var mc = new MongoCollection()... (17/07/2014)
  2. var mc = new MongoCollection()... (13/11/2017)
Enlace
El enlace para compartir es:

Powered by TreeWeb
© TreeWeb 2010. Todos los derechos reservados