Tuesday, November 26, 2013

Add/remove child elements to/from a table in Dojo.

In the define signature of an AMD module I associate "dojo/dom-construct" with domConstruct and then I do the following with domConstruct:

var tr = domConstruct.create("tr", {}, this.table);
var foo = domConstruct.create("td", { innerHTML: "foo" }, tr);
var bar = domConstruct.create("td", { innerHTML: "bar bar bar bar bar bar bar bar bar
      bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar",
      nowrap: "nowrap" }, tr);
var baz = domConstruct.create("td", { innerHTML: "baz" }, tr);
var qux = domConstruct.create("td", { innerHTML: "qux" }, tr);

 
 

Per this a good way to turn around and drop all of the children pushed into this.table would be like so:

while (this.table.hasChildNodes()) {
   this.table.removeChild(this.table.lastChild);
}

No comments:

Post a Comment