使用Meteor {{{member}}}的JS等价物是什么

时间:2016-05-11 12:35:10

标签: mongodb events meteor

我有一个流量助手,它使用find中的反应变量来获取使用id的唯一文档。我的项目按钮模板如下所示:

<template name = "itemButton" >
    <div class = "itemButton" name = {{_id}}>
        {{{title}}}
    </div>
</template>

使用反应变量:

Template.landing.onCreated(function _OnCreated() {
    this.f = new ReactiveVar();
    this.f.set(false);
    const handle = Meteor.subscribe("Feed");
});

现在我在模板中有一个方法有几个itemButton。

Template.landing.events({
    'click .itemButton' : function(event, template){
        alert(event.target.name);
        template.f.set(event.target.name);
    }
});

我希望在帮助器中使用该名称,将该值用作_id。

Template.landing.helpers({
    "GetFocus": function(){
        alert(Template.instance().f.get()); // alerts undefined...
        return(items.find({'_id':Template.instance().f.get()}));
    }
});

所以我希望GetFocus给我生成按钮的文档,我似乎并不那么幸运。如果我能提供任何额外的说明,请告诉我,并且一如既往地感谢您的意见。

1 个答案:

答案 0 :(得分:0)

我有template.f.set(event.target.name);我需要template.f.set(event.currentTarget.getAttribute('data-id'));,其中html使用data-id而不是name。