Along with the text and files, we now send a list of user IDs—users that should be tagged in the post. As mentioned before, they come to the server in the form of a string. We need to use JSON.parse
to convert them into a regular array. The following lines are part of the backend/api/content.js
module:
var form = new formidable.IncomingForm(); form.multiples = true; form.parse(req, function(err, formData, files) { var data = { text: formData.text }; if(formData.pageId) { data.pageId = formData.pageId; } if(formData.eventDate) { data.eventDate = formData.eventDate; } if(formData.taggedFriends) { data.taggedFriends = JSON.parse(formData.taggedFriends); } ...
The content.js
module is the place where formidable
provides the data sent by the frontend. At the end of this code snippet, we reconstructed the array from the previously serialized string.
We can easily go with only that change and store the...