How do I specify using a view with a compiled handlebar in ember.js RC1

随声附和 提交于 2019-12-13 04:28:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!