开发者

Proper way to use $.tmpl in jQuery

I'm using tmpl in开发者_C百科 many places but I see a lot of repeats in my code like

$('#sel').html('');    // cleanup
$.tmpl('template', data).appendTo('#sel');

looks like I'm missing something, this should be possible with $.tmpl only. Any idea?


Why not $('#sel').html($.tmpl('template', data)) ?


In my view it is better to clean up first and then use

$.tmpl('template', data).appendTo('#sel');

Because jquery spec recommends it. Take a look at this piece of doc taken from http://api.jquery.com/jQuery.template/

To insert the rendered template items into the HTML DOM, the returned jQuery collection should not be inserted directly into the DOM, but should be chained with .appendTo, .prependTo, .insertAfter or .insertBefore

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜