我有一个活动,需要在应用程序外部的空间中插入模板。使用Ember-CLI,我们拥有了所有这些精美的预编译模板,因此,我试图弄清楚如何使用它们。
(人类CLI 0.0.42,人类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
那么使用这些模板的正确方法是什么?
以不同的方式提出的这个问题可能已经得到回答:
在没有Ember应用程序的情况下,编译Ember模板字符串并以编程方式运行它?
使用模板和视图,类似的东西似乎可以在另一个视图中工作:
externalView = this.get("container").lookup("view:the-template");
externalView.setProperties({ button: "OK" });
externalView.appendTo($("#here"));
...然后记得以后再销毁()或destroyElement()。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句