【发布时间】:2015-09-02 13:25:33
【问题描述】:
我正在尝试将参数传递给模板助手。该参数似乎已传递,但我无法按照我的意愿使用它。
我这样传递参数:
{{#if unitFieldExists 'profile'}}
{{profile}}
{{/}}
/client/lib/helpers.js 中的帮助程序
Template.registerHelper('unitFieldExists', function(unitField) {
var doc = Units.findOne({_id: this._id }, { unitField : {$exists: true} });
// console tests
console.log(unitField); // Outputs profile
console.log(doc); // Outputs document object
// unitfield if of type string
console.log(typeof unitField + " " + unitField); // string
if (doc.unitField) {
return true;
} else {
return false;
}
});
如果文档包含传递的字段,我想要实现的是返回 true 到 #if。我可能把事情复杂化了,但我仍在学习。
【问题讨论】: