javascript - 如何将参数传递给返回对象的 meteor 助手

标签 javascript meteor

我想知道是否可以将参数传递给 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/

相关文章:

javascript - 使用 Ctrl+v 或右键单击 -> 粘贴检测粘贴的文本

javascript - 尝试在react-redux中构建搜索过滤器

php - Javascript 中的对象可以像 PHP 中的 ArrayAccess/ArrayObject 一样运行吗?

meteor - 如何在 meteor 应用程序中扫描条形码图像

javascript - 在 Meteor 的动态模板中将参数传递给 helper

javascript - Facebook 帖子嵌入呈现但未显示

javascript - promise 永不兑现

meteor - 如何重置使用meteor up 部署的meteor 项目

meteor - 如何部分更新meteor.user.profile?

node.js - meteor JS : Generating emails from templates server-side