问题
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.
So my code looked like this:
App.NewUserController = Em.Controller.extend({});
App.NewUserView = Em.View.extend({
template: Em.Handlebars.compile(NewUserHtml)
});
NewUserHtml is a html/handlebars file loaded through require.js.
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.
I am probably doing something fundamentally anti-rc 1.0...
Any guidance would be appreciated.
回答1:
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'
});
or
App.NewUserView = Ember.View.extend({
template: Handlebars.compile(NewUserHtml)
});
or
App.NewUserView = Ember.View.extend({
templateName: 'some-other-template'
});
You can read more about views here, 'templates' section.
来源:https://stackoverflow.com/questions/14915027/how-do-i-specify-using-a-view-with-a-compiled-handlebar-in-ember-js-rc1