创建反应式阵列会话存储

creating reactive array session storage

本文关键字:存储 会话 阵列 反应式 创建      更新时间:2023-09-26

我正试图根据用户事件排除要在client上显示的文档。

这是我失败的尝试:

Template.documents.events({
  'click #dontShowThisDocument': function () {
    Session.set('excludedDocument', this._id);
  }
});
Template.documents.helpers({
  lists: function () {
    var excludedDocuments = [];
    excludedDocuments.push(Session.get('excludedDocument'));
    return Coll.find({_id:{$nin:excludedDocuments});
  }
});

如何使用meteor创建array会话存储,以便用户能够排除列表reactively上的某些文档?

非常感谢。

会话变量可以容纳一个数组(或者任何对象),这意味着你可以这样做:

Template.documents.events({
  'click #dontShowThisDocument': function () {
    var excluded = Session.get('excludedDocument');
    if ( excluded ) excluded.push(this._id);
    else excluded = [ this.id ];
    Session.set('excludedDocument',excluded);
  }
});
Template.documents.helpers({
  lists: function () {
    return Coll.find({ _id: { $nin: Session.get('excludedDocument') });
  }
});