Meteor 模板助手的全局函数 [英] Global function for Meteor template helper

查看:18
本文介绍了Meteor 模板助手的全局函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经注册了一个这样的全局函数:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆