我尝试的并不重要,我无法让任何助手工作。我正试图让这个工作:
app/helpers/render-component.js
:
import Ember from 'ember';
export default Ember.Handlebars.registerBoundHelper('render-component',
function(record, fieldCfg, options) {
console.log('*** inside renderComponent for ' + record);
return new Ember.Handlebars.SafeString('hello');
});
app/templates/index.hbs
:
{{render-component widget}}
firefox控制台说:
TypeError: helper.apply is not a function
return helper.apply(this, slice.call(arguments, 1)); // vendor.js (line 19908, col 8)
我做错了什么?我的代表是:
"dependencies": {
"handlebars": "~1.3.0",
"jquery": "^1.11.1",
"ember": "1.7.0",
"ember-resolver": "~0.1.7",
"loader": "stefanpenner/loader.js#1.0.1",
"ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4",
"ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2",
"ember-qunit": "0.1.8",
"ember-qunit-notifications": "0.0.4",
"qunit": "~1.15.0",
"bootstrap": "~3.2.0",
"moment": "~2.8.3",
"fastclick": "~1.0.3"
}
将内容重命名为renderComponent
也不起作用。
事实上,这很奇怪。有时它只适用于我的列表中的几个项目,有时它适用于所有项目,有时它会失败...我不明白发生了什么。
答案 0 :(得分:3)
使用ember-cli:http://www.ember-cli.com/#resolving-handlebars-helpers
更改:Ember.Handlebars.registerBoundHelper
至:Ember.Handlebars.makeBoundHelper
区别在于"注册"用于显式定义一个助手,默认情况下ember不会自动解析,即那些不包含破折号的助手。因为您的助手名称中有破折号,所以不需要注册步骤。