想要在用户集合中的请求数组中访问对象

时间:2017-02-18 09:24:07

标签: javascript html mongodb meteor

  

我想创建一个事件,通过单击中的“接受”   termplate我想得到请求数组的相应对象   用户集合的简介

我的用户集合(accounts-password)

的此个人资料部分
{
    "profile": {
        "name": {
            "first_name": "Vibhor",
            "last_name": "Yadav"
        },
        "college_name": "ssit",
        "gender": "MALE",
        "friends": [],
        "requests": [{
            "id": "z6rDkvayDA5Ckoeab",
            "name": "Nitin Gupta"
        }],
        "requested": [{
            "id": "M6edD427rG9WwhfNh",
            "name": "suraj Kumar"
        }]
    }

打印请求的模板

<template name = "notification">
    <div id="req-main-div">
        <ul>
            {{# each username in reqList}}
                <li>
                    <div id="req-user-name" value={{username.name}}>{{username.name}}</div>
                    <div id="accept">accept</div>
                    <div id="delete">delete</div>
                </li>
            {{/each}}
        </ul>
    </div>
</template>

模板的帮助

Template.notification.helpers({
    reqList:function () {
        var User = Meteor.user();
        return User.profile.requests;
    }
});

我试过的方法

 Template.notification.events({
        'click #accept':function(){
            console.log(document.getElementById('req-user-name').value);
            Meteor.call('accept_request',this);
        }
    });

我也无法访问DOM

accept_request:function(accept){
    if(!Meteor.userId())
    {
      throw new Meteor.Error('not-authorized','you are not signed in');
    }
    var user = Meteor.user();
    console.log(accept);
}

我在控制台上得到这个

undefined//for DOM of # accept
Object// for accept in accept_request method
main: ()
__proto__: Object

0 个答案:

没有答案