在运行时在Ember 2.5中动态编译HTMLBars模板 [英] Dynamically compile a HTMLBars template at runtime in Ember 2.5

查看:167
本文介绍了在运行时在Ember 2.5中动态编译HTMLBars模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在运行时动态编译(然后渲染)HTMLBars模板,在Ember 2.5的客户端上。

I want to dynamically compile (and then render) a HTMLBars template at runtime, on the client in Ember 2.5. How can I do this?

推荐答案

构建关于Kingpin2K的答案使用HTMLbars在ember中编译模板客户端

Building off of Kingpin2K's answer to Compile template client side in ember using HTMLbars:

对于某些背景,可能有用的是返回使用Ember 1.10编译模板。我们仍然需要加载 ember-template-compiler.js 。添加

For some background, it might be useful to refer back to Compiling Templates with Ember 1.10. We'll still need to load ember-template-compiler.js. Add

  app.import('bower_components/ember/ember-template-compiler.js');

到您的 ember-cli-build.js

然后你可以这样写一个组件:

Then you can write a Component like this:

import Ember from 'ember';

export default Ember.Component.extend({

  layout: Ember.computed(function() {
    return Ember.HTMLBars.compile(
      '{{foo-bar}} <span>' + 'hello' + '</span>'
    );
  }),

});

这个解决方案可能会在Ember的后续更新中崩溃,这取决于Ember模板编译过程是如何变化的 Glimmer 2 的到来。

This solution will likely break in future relases of Ember, depending on how the Ember Template compilation process changes with the advent of Glimmer 2.

这篇关于在运行时在Ember 2.5中动态编译HTMLBars模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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