如何在流星点击时显示图标? [英] How to show an icon on click in meteor?

查看:203
本文介绍了如何在流星点击时显示图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在流星中构建一个应用程序,我在模板中有一个以下的代码。

I am building an application in a meteor and I have a below code in the template.

 <h3>
   <b>
     <a class="viewed" href="/jobdetails/{{_id}}">{{title}}</a>
   </b>
   &nbsp;&nbsp;
   <span class="job-type part-time">Part Time</span> 
 </h3>


<div id="eyeIcon">
  <span class="glyphicon glyphicon-eye-open" style="color:green"></span>    
 </div>

我需要在点击href标签并显示glyphicon eye图标并将其存储到集合中。我怎样才能做到这一点?我是新的流星。任何人都可以帮助我,我们怎么能使用流星。先感谢。

I have to display the glyphicon eye icon on click of a href tag and storing them into a collection. How can I do that? I am new to the meteor. Can anyone help me how can we do it using Meteor. Thanks in advance.

推荐答案

<h3>
   <b>
     <a class="viewed" href="/jobdetails/{{_id}}">{{title}}</a>
   </b>
   &nbsp;&nbsp;
   <span class="job-type part-time">Part Time</span> 
 </h3>

{{showIcon}}
<div id="eyeIcon">
  <span class="glyphicon glyphicon-eye-open" style="color:green"></span>    
 </div>
{{/if}}


Template.yourTemplate.helpers({
  'showIcon':  function() {
    return Session.get('showIcon');
  },
});
Template.yourTemplate.events({
  'click .viewed': function(event, instance) {
    event.preventDefault();
    Session.set('showIcon', true);
  },
});

请注意,我使用会话在整个应用程序中持久化您的数据。如果您还希望永久保留此值,而不是使用集合。

Please note that I have used session to persist your data throughout the app. If you also want to retain this value permanently than you can use collections.

此外,如果您要保留它的值以在页面刷新时持久保存,使用Session.setPersistent( https://github.com/okgrow/meteor-persistent-session)而不是Session.set

Also, if you to just retain it's value to be persisted on page refresh also, then you can use Session.setPersistent (https://github.com/okgrow/meteor-persistent-session) instead of Session.set

这篇关于如何在流星点击时显示图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆