我有这个代码
模板['产品'].helpers(
“变体”:->
variant_value = Session.get('variant')
如果变量值
返回变量值
别的
Session.set('变体',@lowest_variant())
'已选择':->
如果 @variant() == opt1_name
返回真
否则返回 false
我想在 isSelected 中使用变体方法。上面的代码不起作用。知道如何创建一个函数以便它可以用于不同的辅助方法吗?
最佳答案
但是如何创建一个函数以便它可以用于不同的辅助方法? 只需创建一个全局函数
我不是 CoffeeScript 专家。
但是在 meteor 上,这就是全局变量发生的情况,来自 docs .
Per the usual CoffeeScript convention, CoffeeScript variables are file-scoped by default (visible only in the .coffee file where they are defined.)
因此,您可以在使用该帮助程序的 .coffee 文件的顶层创建该函数。
纯javascript
variant = function(){
//code to be used on diferents helpers
}
关于javascript - 复用了 Meteor JS 中的部分代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29529279/