简体   繁体   English

流星,使用Javascript为Gravatar创建哈希键

[英]Meteor, Javascript to create Hash Key for Gravatar

I read some postings about creating hash keys in jQuery. 我读了一些有关在jQuery中创建哈希键的文章。

How to create a hashed email in jQuery? 如何在jQuery中创建哈希电子邮件?

So I did this in my meteor to get the Gravatar profile photo from github email address. 因此,我在流星上进行了此操作,以便从github电子邮件地址获取Gravatar个人资料照片。 But it is not working. 但这是行不通的。 I think Hash Key is produced correctly but I am not sure how to do this in Meteor. 我认为哈希密钥生成正确,但是我不确定如何在Meteor中执行此操作。

Following is my trying. 以下是我的尝试。 in HTML file 在HTML文件中

      <template name="messages">
         {{#each messages}}
       <strong>{{name}}</strong> : {{message}}<br>
         {{/each}}
         <img src=img_add/>
      </template>

in Javascript file 在Javascript文件中

 var hash = CryptoJS.MD5(git_email);
 var img_add = "http://www.gravatar.com/avatar/" + hash;

This produces a broken link. 这将产生断开的链接。

How do I insert profile Gravatar photo in meteor, given email address? 给定电子邮件地址,如何在流星中插入个人资料Gravatar照片?

You need to use a helper just like in the hello world example. 您需要像在hello world示例中一样使用助手。

Your client side javascript: 您的客户端javascript:

Template.messages.img_add = function() {
    var hash = CryptoJS.MD5(git_email);
    return img_add = "http://www.gravatar.com/avatar/" + hash;
}

Your template: 您的模板:

 <img src={{img_add}}/>

Or if you want to use it in the {{#each }} loop, use this slight modification & make sure your {{img_add}} helper is within the {{#each }} block. 或者,如果您想在{{#each }}循环中使用它,请使用此稍作修改并确保您的{{img_add}}帮助器在{{#each }}块内。 I'm not too sure how your doing the variables, but as long as the git_email is in each of your documents you're looping over. 我不太确定您如何执行变量,但是只要git_email在每个文档中,您就可以循环遍历。

Template.messages.img_add = function() {
    var hash = CryptoJS.MD5(this.git_email);
    return img_add = "http://www.gravatar.com/avatar/" + hash;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM