developing dynamic array session storage

I'm attempting to filter out certain documents from appearing on the client side based on user interaction.

Here is an example of what I've tried but unfortunately it didn't work:


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

Is there a way to store excluded document IDs in an array using Meteor, so that users can dynamically exclude specific documents from a list?

Thank you for your help!

Answer №1

An array can be stored in a Session variable, allowing for dynamic operations like the following:

Template.docs.events({
  'click #hideDoc': function () {
    var hiddenDocs = Session.get('hiddenDocuments');
    if (hiddenDocs) hiddenDocs.push(this._id);
    else hiddenDocs = [this.id];
    Session.set('hiddenDocuments', hiddenDocs);
  }
});

Template.docs.helpers({
  displayed: function() {
    return Docs.find({_id: {$nin: Session.get('hiddenDocuments')}});
  }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Jquery method to extract and modify text within an HTML opening tag

As an example, let's consider <img onclick="remClicked(this)" src="~/images/chrest.png" /> I am interested in replacing onclick="remClicked(this)" src="~/images/chrest.png" with another text using either javascript or jquery. Is this possible? ...

Using Ajax to send data to a PHP script

I am interested in implementing an AJAX call to a PHP script each time a specific button is clicked. The buttons correspond to different directions - right, left, top, and bottom, represented by divs named r, l, t, and b. I have attempted the code below ...

utilizing the printf function both before and within a loop in x86-64 assembly

I'm struggling with correctly utilizing printf in the multInts function. The objective of the function is to multiply the first element of the first array with the first element of the second array and continue this process for the entire array. Howev ...

JSP allows for creating a public array list

I am having trouble displaying an array on the screen in JSP. The array (ans) is not being recognized and I am new to JSP. I would like the array list to be public, similar to Java. Is this possible? I need to declare the array in the JSP file so that I c ...

Resizing the Three.js canvas without impacting the renderer size or content scaling: A guide

I am currently in the process of creating a website using a Three.js canvas that covers the entire viewport. My goal is to keep the visuals consistent even when resizing the window, without any scaling. Here is my current approach: renderer.setSize(wind ...

Tips for updating the value of a nested object within an array using JavaScript

I'm currently working with React to update the state when a user triggers the delete button. The data structure involves nested objects inside another nested object within an array. const data = [ { id: 2, adminId: 2, roleId: 1, stor ...

"An issue with ng-controller in AngularJS causing a simple error

Currently, I'm in the process of learning angularJS. While ng-app and ng-model are functioning properly, I've encountered an issue with ng-controller. Despite my efforts, I can't seem to pinpoint where I've gone wrong. My code isn' ...

Include Firebug Lite in JSFiddle and have it launch in a minimized state

Firebug used to be the top development tool for web design, but now most major browsers have their own advanced Developer Tools built in. However, there are still times when I find it more convenient to include the Firebug script when working with code on ...

Transfer the HTML5 FullScreen (MAP) feature onto a separate display

I'm trying to integrate a leaflet map into my AngularJS Application, but I've hit a roadblock. My goal is to move the Fullscreen feature of the Map to a second screen (if one is available), allowing users to interact with the application on the ...

inability to conceal a two-dimensional marker array within Google Maps API v3

I need some help with my marker that refuses to hide Even after using setMap, my marker is still visible on the map Here is the error message from the console Please assist! Thank you in advance markers[i][j].setMap(null); markers.setMap(null); va ...

The mysterious outcome of utilizing CI with Mongo remains a puzzle

I am a beginner exploring MongoDB and attempting to integrate it with CI. I am following a tutorial found here, but when I execute my controller, I receive the following output: MongoCollection Object ( [w] => 0 [wtimeout] => 10000 ) I am u ...

AngularJS's ScrollTo function allows users to scroll to a specific

Trying to implement a quick nav that smoothly scrolls to different sections on the page when a link is clicked. Currently using a guide provided by Treehouse for reference. $("#quickNav a").click(function(){ var quickNavId = $(this).attr("href"); ...

Using tsc with skipLibCheck flag will still perform checks on the node_modules directory

When I run the CLI command npx tsc --noEmit --skipLibCheck, I still encounter errors: node_modules/@types/node/util.d.ts:1631:41 - error TS1005: '(' expected. 1631 keys(): IterableIterator<string>; ...

Node.js is throwing an error when attempting to create a MongoDB database

I am facing an issue with connecting to and creating a database for my Node.js project. I have successfully installed MongoDB, but I am encountering an error when trying to create the database: D:\nodejs>node demo_create_mongo_db.js D:&bs ...

pm2 initiates two identical processes using distinct versions

I am currently using pm2 version 4.2.3 Upon executing the command: pm2 start node launchers/engine_launcher.js --name "engine", it initiates the following processes: id │ name │ namespace │ version │ mode │ pid - ...

Creating an alias for a field name in Mongo Compass

Currently working in Mongo using Compass, I am attempting to implement an alias for a field name based on suggestions found on Stack Overflow. For instance, within my people collection, there exists a "n" property that contains the value of "name". I hav ...

Restrict the hide/show functionality on a div to only operate within its specific radio group, without impacting the other radio groups within the form

I created a form with 3 radio groups that show different sets of divs based on the selection made. The issue I'm facing is that the current code hides radio content divs across all 3 radio groups. How can I fix this? My goal is to display all "Yes" c ...

I am encountering an issue where propData in Vue Jest is returning as undefined

I have encountered an issue while passing the propData in my jest test file for a Vue component. It seems that the propData is not being set to the component and instead, I am receiving an error saying "cannot read property of clouds of undefined." Could i ...

Returning and Embedding a 2D array object in C++

I am having trouble returning an array data member from a smaller 2D Array object and attempting to insert the array into a larger 2D array object. However, I have encountered two issues. Firstly, I am unable to figure out the proper syntax to return the ...

retrieving the values listed on the current v-data-table page

In my vuejs2 project, I am utilizing a v-data-table to display information in columns about a large number of users. Each page shows 25 users, with a total exceeding 60,000 individuals. I am wondering if there is a way to retrieve the list of users curre ...