如何在ember.js RC1中指定使用带有已编译车把的视图 [英] How do I specify using a view with a compiled handlebar in ember.js RC1
问题描述
我正在尝试将pre2应用程序移植到1.0.0 rc。我的应用程序设置的方式如下:我所有的模板都编译到自己的视图中。
I am trying to port a pre2 application to 1.0.0 rc. They way my application is setup is as follow: all my templates are compiled into their own view.
所以我的代码如下:
App.NewUserController = Em.Controller.extend({});
App.NewUserView = Em.View.extend({
template: Em.Handlebars.compile(NewUserHtml)
});
NewUserHtml是通过require.js加载的html /把手文件。
NewUserHtml is a html/handlebars file loaded through require.js.
由于文件被直接编译到模板中,因此不包含< script type = text / x-handlebars…>
标签。
Since the file is directly compiled into the template it doesn't include a <script type="text/x-handlebars"…>
tag.
我知道我需要覆盖路线的渲染功能,但是我看到的选项似乎要求我指定一个模板,而我实际上并没有一。就我而言,因为模板已经在我的视图中,所以我正在寻找一种仅指定要使用的视图的方法。
I understand that I need to override the render function of my route, but the options I have seen seem to require that I specify a template and I don't really have one. In my case since the template is already in my view, I am looking for a way to just specify the view to use.
我可能从根本上做些反rc的操作1.0 ...
I am probably doing something fundamentally anti-rc 1.0...
任何指导将不胜感激。
推荐答案
鉴于NewUserHtml只是带有handlebars标签的纯文本,因此您应该能够在视图中执行以下操作:
Given that NewUserHtml is just plain text with handlebars tags, you should be able to do something like this in your view:
Ember.TEMPLATES['NewUser'] = Handlebars.compile(NewUserHtml);
App.NewUserView = Ember.View.extend({
templateName: 'NewUser'
});
或
App.NewUserView = Ember.View.extend({
template: Handlebars.compile(NewUserHtml)
});
或
App.NewUserView = Ember.View.extend({
templateName: 'some-other-template'
});
您可以阅读有关视图的更多信息此处,模板部分。
You can read more about views here, 'templates' section.
这篇关于如何在ember.js RC1中指定使用带有已编译车把的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!