【问题标题】:How can I use templates outside of the render pipeline如何在渲染管道之外使用模板
【发布时间】:2015-02-05 09:55:44
【问题描述】:

我有一个事件需要在应用程序外部的空间中插入模板。使用 Ember-CLI,我们拥有所有这些出色的预编译模板,因此我正在尝试找出如何使用其中的一个。

(Ember-CLI 0.0.42,Ember 1.7.0)

我发现我可以像这样得到预编译的模板函数:

import TheTemplate from 'app/templates/the-template';

但是,如果我按照 Handlebars 网站上的说明调用它,则会收到错误消息。

var context = { button: "OK" };
var str = TheTemplate(context);

Uncaught TypeError: Cannot read property 'push' of undefined

那么使用这些模板的正确方法是什么?

【问题讨论】:

  • Handlebars.template("the-template") 也获取模板。

标签: ember.js handlebars.js ember-cli


【解决方案1】:

这个问题以不同的方式提出,可能已经回答了:

Compile Ember template string and running it programmatically, without an Ember application?

同时使用模板和视图,这样的事情似乎可以在另一个视图中工作:

externalView = this.get("container").lookup("view:the-template");
externalView.setProperties({ button: "OK" });
externalView.appendTo($("#here"));

...然后记得稍后再去destroy() 或destroyElement()。

【讨论】:

  • 只是强调一下,这只适用于在应用程序之外呈现。
猜你喜欢
  • 2014-04-11
  • 2017-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-08
相关资源
最近更新 更多