流星模板助手的全局功能 [英] Global function for Meteor template helper
问题描述
我已经注册了这样的全局功能:
I have registered a global function like this:
Handlebars.registerHelper('dialogBoxOptions', function (callbackFunctionName){
return {
callBack: callbackFunctionName
};
});
但是当我尝试按以下方式访问它时,我未定义dialogBoxOptions
but when I try to access it as below I get dialogBoxOptions is not defined
Template.myLlist.helpers({
dOpt: dialogBoxOptions('dlgCB')
});
我已经尝试将其用作全局把手帮助程序和常规的javascript函数,但得到的结果相同.
I have tried this as a global handlebars helper and a regular javascript function but get the same result.
推荐答案
您无法通过这种方式访问车把助手,而可以在模板中访问它们:
You can't access handlebars helpers this way you can access them in the template:
<template name="myList">
{{dialogBoxOptions.callback 'something'}}
</template>
如果要像现在一样在助手中访问它,则应该注册一个全局方法.您可以将其放在/lib/helpers.js
If you want to access it in your helper like you are doing now you should register a global method instead. You could put this in a file like /lib/helpers.js
dialogBoxOptions = function (callbackFunctionName){
return {
callBack: callbackFunctionName
};
}
此外,如果您要创建全局模板帮助器,语法现在为:
Also if you want to make a global template helper, the syntax is now:
Template.registerHelper("dialogBoxOptions", function (param2) {
return true;
});
这篇关于流星模板助手的全局功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!