Mik*_*ski 23

您可以在中注册新模板Ember.TEMPLATES.然后他们将可以查看.

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

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());
  });
}
Run Code Online (Sandbox Code Playgroud)

而已.


joe*_*der 7

我只是在寻找相同的东西,即将与下面的片段玩

credit:borismus on github https://gist.github.com/2165681

<script>
/*
 * Loads a handlebars.js template at a given URL. Takes an optional name, in which     case,
 * the template is added and is reference-able via templateName.
 */
function loadTemplate(url, name, callback) {
  var contents = $.get(url, function(templateText) {
    var compiledTemplate = Ember.Handlebars.compile(templateText);
    if (name) {
      Ember.TEMPLATES[name] = compiledTemplate
    } else {
      Ember.View.create({ template: compiledTemplate }).append();
    }
    if (callback) {
      callback();
    }
  });
}
</script>
Run Code Online (Sandbox Code Playgroud)