在 javascript (meteorJs) 中点击时传递按钮 ID

Passing button id on click in javascript (meteorJs)

我有以下 bootstrap 元素:

<template name = "myAwesomeTemplate">    
<input class="buy btn span4" id= "cat" value ="something" /> 
<input class="buy btn span4" id="dog" value = "something else" /> 
</template>

我正在尝试将 "id" 属性(在此示例中为猫或狗 - 取决于我单击的按钮)传递给方法函数:

Template.myAwesomeTemplate.events({nt 
    'click .buy' : function  (event, template) {
      Meteor.call('buy', this, $(this).attr(id));
    }
});

我已经尝试了 this.idtemplate.find('.buy') - 没有确切的词。有人知道怎么做吗?

Meteor.methods({
     buy: function(thisref,idref) {
        console.log(idref);
});

单击第一个输入元素时,控制台应输出 "cat",单击第二个输入元素时,应输出 "dog"。

此外,在这种情况下 this return 到底是什么意思?它似乎是 returning 这个特定模板可以访问的全部数据。

尝试使用 $(event.currentTarget) 获取当前点击的元素 jquery 引用,在此 .buy

Template.myAwesomeTemplate.events({
    'click .buy' : function  (event, template) {
      Meteor.call('buy', this, $(event.currentTarget).attr("id"));
    }
});

$(this)在事件处理程序中returns模板数据

好的,我找到了答案.... 这有效:

Template.myAwesomeTemplate.events({
    'click .buy' : function  (event, template) {
      Meteor.call('buy', this, event.target.id);
    }
});