Is it possible to load a Handlebars template via Ajax?

前端 未结 3 592
闹比i
闹比i 2020-12-02 23:36

I would like to load additional templates on the fly. Is it possible?

3条回答
  •  北海茫月
    2020-12-03 00:39

    You can register new templates in Ember.TEMPLATES. They will then be available to views.

    An excerpt from my code (jQuery Ajax handler):

    success: function(data) {
      $(data).filter('script[type="text/x-handlebars"]').each(function() {
        templateName = $(this).attr('data-template-name');
        Ember.TEMPLATES[templateName] = Ember.Handlebars.compile($(this).html());
      });
    }
    

    That's it.

提交回复
热议问题