Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 创建反应式阵列会话存储_Javascript_Arrays_Mongodb_Meteor - Fatal编程技术网

Javascript 创建反应式阵列会话存储

Javascript 创建反应式阵列会话存储,javascript,arrays,mongodb,meteor,Javascript,Arrays,Mongodb,Meteor,我试图根据用户事件排除要在客户端上显示的文档 这是我失败的尝试: Template.documents.events({ 'click #dontShowThisDocument': function () { Session.set('excludedDocument', this._id); } }); Template.documents.helpers({ lists: function () { var excludedDocuments = [];

我试图根据用户事件排除要在
客户端上显示的文档

这是我失败的尝试:

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创建
数组
会话存储,以便用户能够反应性地排除列表上的特定文档


非常感谢。

会话变量可以保存数组(或任何对象),这意味着您可以执行以下操作:

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') });
  }
});

你是说
Session.get('excludedDocument')
?helloo@DavidWeldon谢谢你的回复。。yapp我正在尝试将每个
会话.get('excludedDocument')
推送到数组
excludedDocuments
。。。抱歉,我不明白你的问题,@KarinaL在调用
会话时,上面的代码不包括
排除文档
的引号。get
。我不知道这是你在提问时犯的错误,还是你的代码中出现了错误。无论哪种方式,这看起来都很可疑。你能描述一下你的尝试是如何失败的吗?正如我现在读到的,您每次都在实例化一个新数组,这很奇怪。如果只想有一个数组,在选择值时将其推入其中,则应提升上述范围内的声明。@Kyll列表未更新…应排除的文档仍保留在列表中,,,