PDA

View Full Version : simple fn of jquery equiv.



hello2008
8 Dec 2009, 6:52 PM
I want to use Ext Core API to write a test fn named table.


...
"table": function(){
// in a 40-iteration for loop:
// create a table with the class "madetable", and append it to the DOM
// add a row with one cell to the table. the cell content should be "first"
// add a new cell before the first cell in the row.
//
// return the length of the query "tr td"
},
...


// jquery version for reference


...
"table": function(){
for(var i = 0; i < 40; i++){
$("<table class='madetable'></table>")
.appendTo("body")
.html("<tr><td>first</td></tr>")
.find("tr").prepend("<td>before</td>");
}
return $("tr td").length;
},
...


I found it's not easy for me to write a ext core version of jquery equiv.:)

some requirements:
write a simple and concise fn, shortest is best
only write codes within function body
Ext Core API only, don't use any Ext.apply/applyIf/override/extend

Animal
9 Dec 2009, 1:29 AM
You seriously just want to create 40 consecutive tables in your application?

Animal
9 Dec 2009, 1:42 AM
But if you insist:



function() {
for (var i = 0; i < 40; i++) {
Ext.getBody().createChild("<table><tbody><tr><td>first</td></tr></tbody></table>")
.child("tr")
.insertHtml('afterBegin', '<td>before</td>');
}
return Ext.query("tr td").length;
}

hello2008
9 Dec 2009, 8:22 AM
You seriously just want to create 40 consecutive tables in your application?

Actually just for test of Taskspeed (http://www.extjs.com/forum/showthread.php?t=72966) :)


But if you insist:


function() {
for (var i = 0; i < 40; i++) {
Ext.getBody().createChild("<table><tbody><tr><td>first</td></tr></tbody></table>")
.child("tr")
.insertHtml('afterBegin', '<td>before</td>');
}
return Ext.query("tr td").length;
}


Thanks for your quick reply. :) seems you merged step1(append table dom node) and step2(insert a row with one cell),
so I have to write like this:


function() {
for (var i = 0; i < 40; i++) {
Ext.getBody().createChild('<table class="madetable"></table>')
.createChild('<tr><td>first</td></tr>')
.child('tr')
.insertHtml('afterBegin', '<td>before</td>');
}
return Ext.query("tr td").length;
}