可以通过Ajax加载Handlebars模板吗? [英] Is it possible to load a Handlebars template via Ajax?

查看:108
本文介绍了可以通过Ajax加载Handlebars模板吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载其他模板。可以吗?

解决方案

您可以在中注册新模板Ember.TEMPLATES



我的代码摘录(jQuery Ajax处理程序):

 成功: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());
});
}

就是这样。


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

解决方案

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.

这篇关于可以通过Ajax加载Handlebars模板吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆