我只是尝试使用Handlebars帮助器渲染视图。应用程序运行时我一直收到错误:
Uncaught TypeError: Cannot call method 'apply' of undefined
车把:
<script type='text/x-handlebars'>
{{outlet}}
</script>
<script type='text/x-handlebars' id="index">
INDEX
{{my-component-helper}}
</script>
<script type='text/x-handlebars' id="myComponentHelper">
I'm here
</script>
JS:
App = Ember.Application.create();
Ember.Handlebars.helper('my-component-helper', App.MyComponentHelperView);
App.MyComponentHelperView = Ember.View.extend({
templateName:'myComponentHelper'
});
这是一个说明问题的JSbin: http://jsbin.com/edUm/1/edit
答案 0 :(得分:1)
您的问题是订购。在您的版本中App.MyComponentHelperView
在解释代码时未定义。试试这个:
App = Ember.Application.create();
App.MyComponentHelperView = Ember.View.extend({
templateName:'myComponentHelper'
});
Ember.Handlebars.helper('my-component-helper', App.MyComponentHelperView);