开发者

Is there a method for jQuery .tmpl() completed event handling?

I'd like to ask, how can i make a $.tmpl ready function?

In my code I pass the ajax json to my createForm function.

var doFunction = {
new: function() { 
    $.ajax({
      url: 'index.php?...',
      success: function(data) {
        createForm(data).appendTo($("#whitespace"));
        $("#whitespace").click(function(){
            $(this).empty().hide();
        });
        $("#popup").click(function(e){
            e.stopPropagation();
     开发者_如何学编程   });
        $("#whitespace").show();
      }
    });
},

The createForm function

function createForm(data) {
var $container = $('<div id="popup"></div>');
var $content = $('<article></article>');
$.get('mydomain.com/formcreator.htm', function(template) {
  $.tmpl(template, data).appendTo($content);
});
$content.appendTo($container);
return $container;
}

But if I tell the $container to $container.find(".tabs").tabs(); - it contains an <div class="tabs>...etc...</div>.

I think the problem is I did not catched the $.tmpl finish event.

Is there a success event of the $.tmpl?

Please help me in this.


Thanks for @Aleksi Yrttiaho for this, the solution is turning off the asynchronous ajax request, and use synchronous instead of it.

$.ajax({ url: 'domain.com/formcreator.htm',
success: function(template) {
    $.tmpl(template, data).appendTo($content);
},
async: false
});


You should try this:

success: function(data) {
        createForm(data).appendTo($("#whitespace"));
        $.fn.ready(function(){
            //your append callback function
        });
}

It works nicely for me.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜