0

大家好,我已经尝试过这种方法来从 Meteor.users 数组中获取信息,但它不起作用,我不知道如何解决这个问题。提前致谢!

发布用户

Deps.autorun(function (handle) {

Meteor.publish('directory', function () {
  if (this.userId) {
  var user = Meteor.users.findOne(this.userId);
  var x = user.profile.x;
  return Meteor.users.find({"profile.x": x});
  } else {
    handle.stop();
  }
});
});

Meteor.users.allow({

  remove:function() {
    var user = Meteor.user();
    var x = user.profile.x;
    if(x === "admin") {
      return true;
    } else {
      return false;
    }
    },
});

帮手:

listTeam: function () {
    var userTeam = Meteor.users.find({}).fetch();
    return _.map(userTeam || [], function(user) { return user.emails[0].address || user._id;});
 },

模板:

<ul>
{{#each listTeam}}
<div>
<li id="item">{{this}}</li><button id="deleteTeam" class="button">Delete</button>
</div>
{{/each}}
</ul>

第一种方法:

'click #deleteTeam': function (event, template) {
    var id = template.data._id;
    Meteor.users.remove({_id:id});

  }

返回未定义(仅在迭代的第一项中)

我已经尝试过使用 jQuery,但它没有用,因为我只获得了电子邮件地址和第一项。(我没有迭代 id,我认为这似乎不是一个好的解决方案)。

4

1 回答 1

0

在模板事件函数中,您可以使用它来获取实例数据。例子:

'click #deleteTeam': function (event, template) {
    var id = this._id;
    Meteor.users.remove({_id:id});
}

或者更短:

'click #deleteTeam': function () {
    Meteor.users.remove({_id: this._id});
}

如果您遇到更多问题,则可能是权限问题,我建议使用此模式:

Meteor.users.allow({
  remove: function(userId, doc) {
    var user = Meteor.users.findOne({_id: userId});
    return user ? user.profile.admin : false;
  }
});
于 2013-10-15T18:15:59.103 回答