简体   繁体   中英

Using Ember view helper in handlebars template with global var

Is there any way to reference an Ember view in the handlebars view helper without using the Ember Application global var? I'm getting the error below after precompiling my handlebars templates and minifying my Ember code using Grunt. This seems to be because the Ember global var is shortened to 'a' where the Handlebars template still refers to 'App.View'.

MyView.hbs:

{{#each controller}}
  {{view App.MyChildView}}
{{/each}}

MyChildView.hbs:

<div>Irrelevant HTML</div>

JS:

App = Ember.Application.Create();  
App.MyView = Ember.View.extend({...

App.MyChildView = Ember.View.extend({...

Error:

Uncaught Error: assertion failed: Unable to find view at path 'MyChildView'


Solution:

Found a solution to this by using the render helper instead of view.

MyView.hbs:

{{#each controller}}
  {{render "MyChildView"}}
{{/each}}

The handlebars {{view}} helper can accept a string instead of a constant. So try:

{{#each controller}}
  {{view "App.MyChildView"}}
{{/each}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM