Meteor 模板助手的全局函数 [英] 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;
});
这篇关于Meteor 模板助手的全局函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!