[英]ember-cli call a makeBoundHelper function in javascript
I have an ember-cli helper function: translate-i18n that I am nicely using in my hbs templates as an accessory helper to dockyards i18n translation library. 我有一个ember-cli helper函数:translation-i18n,我很高兴在我的hbs模板中使用它作为船坞i18n翻译库的辅助助手。
The helper I created takes the word as an argument and just provides for a few fallback situations (ex if a translation is missing, it will fire an airbrake error). 我创建的帮助程序将单词作为参数,并且仅提供了一些后备情况(例如,如果缺少翻译,则将引发空刹车错误)。
My helper is working fantastically when used within hbs templates, but it seems like it is impossible to call it from a JS file, specifically another helper file. 在hbs模板中使用我的帮助程序时,它的工作异常出色,但是似乎无法从JS文件(特别是另一个帮助程序文件)中调用它。 In a nutshell, the problem is this:
简而言之,问题是这样的:
Ember.Handlebars.makeBoundHelper(translate);
Ember.Handlebars.makeBoundHelper(translate);
创建帮助器Ember.Handlebars.makeBoundHelper(translate);
the helper is not accessible using Ember.Handlebars.helpers .... so I can't call it that way. export default Ember.Handlebars.registerBoundHelper('translate', translate());
export default Ember.Handlebars.registerBoundHelper('translate', translate());
I can then access my helper from anywhere, but suddenly the container is not defined, and I no longer can get at the dockyards i18n (t helper), as this line throws an error: var t = this.container.lookup('utils:t');
var t = this.container.lookup('utils:t');
Any suggestions/pointers/observations would be greatly appreciated! 任何建议/指针/观察将不胜感激!
If you have a handlebar helpers registered then you can access them from JS like 如果您已经注册了车把帮手,则可以从JS访问它们,例如
For eg : If you have a helper named ' doSomething
', 例如:如果您有一个名为“
doSomething
”的助手,
Ember.Handlebars.registerBoundHelper('doSomething', function (args) {
return something;
});
You can call the helper from JS like the below 您可以像下面这样从JS调用帮助程序
Ember.Handlebars.helpers.doSomething(args);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.