我想知道是否可以将参数传递给 Meteor Helper 并在 HTML 中插入返回对象的属性,而不仅仅是返回最终值。我有这样的东西:
HTML:
<Template name ="conversationList">
{{#each conversation}}
{{getName.userName convStarterId}} convStarterId its a property of conversation object
{{/each}}
</Template>
助手:
Template.conversationList.helpers({
getName: function(Id){
return Members.findOne({userId:Id}) // the Object returned have a property userName},
conversation: function() { //return info from another collection
}
});
我的 html 的第三行似乎不起作用...
最佳答案
这应该使 userName
在您的模板中可用:
<template name="conversationList">
{{#each conversation}}
{{getName convStarterId}}
{{/each}}
</template>
Template.conversationList.helpers({
getName: function(Id){
return Members.findOne({userId:Id}).userName;
},
conversation: function() {
...
}
});
关于javascript - 如何将参数传递给返回对象的 meteor 助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36610218/