I've been searching the docs for YUI3, but I cannot seem to figure out how to create a document fragment. Should I just use the document object开发者_Python百科 itself? I would like to treat it as a YUI Node object.
If you want to create a new empty docfrag, this should work:
var frag = Y.all([]).toFrag();
frag
is then a Node instance wrapping the docfrag.
I think this is equivalent to Luke's answer (I just find it a little more readable)
var frag = Y.one(document.createDocumentFragment());
I'm pretty sure you're looking for this the NodeList.toFrag() method. The toFrag source code is here and the underlying _nl2frag (NodeList to Frag) code is here.
I haven't used it myself and didn't find examples, but it looks pretty straight forward. I assume you would just appendChild it into another node.
var docFrag = Y.Node.create('<div id="foo"><p>Bar</p></div>');
Would work as well. Y.Node.create can do just about anything. Recently ran into this issue with very new chrome versions, easy work around, however:
http://yuilibrary.com/projects/yui3/ticket/2529368
精彩评论