Recursive append strategy

This commit is contained in:
斟酌 鵬兄 2016-02-22 07:55:17 +08:00
parent 7af43e256c
commit c274018645
1 changed files with 25 additions and 21 deletions

View File

@ -8,6 +8,27 @@
/* @type {Dandelion.IDOMElement}*/
var IDOMElement;
var appendR = function( container, elements )
{
if( elements instanceof Array )
{
var l = elements.length;
for( var i = 0; i < l; i ++ )
{
elements[i] && appendR( container, elements[i] );
}
}
else if( typeof elements == "string" )
{
container.appendChild( _createTextNode( elements ) );
}
// append child, do not do any error handling!
else if( elements )
{
container.appendChild( elements );
}
};
var wrap = function ( wwith, id, wclass, elements, iKeys )
{
var tmp = document.createElement( wwith || "div" );
@ -41,26 +62,9 @@
if( elements )
{
// is array?
if(elements instanceof Array)
{
var l = elements.length;
for( var i = 0; i < l; i ++ )
{
elements[i] && tmp.appendChild( elements[i] );
}
}
// else if string
else if( typeof elements == "string" )
{
tmp.appendChild(_createTextNode(elements));
}
// else append child, do not do any error handling!
else if( elements )
{
tmp.appendChild( elements );
}
appendR( tmp, elements );
}
return tmp;
};