I am making a list right now.
Users will be able to search and then click on the searched item to add the corresponding id to the their list.
This is the following code I have written.
Template.searchedItem.events
'click .addToList': function (event, template) {
event.preventDefault();
// _id of the List
var listId = Template.parentData(1)._id;
console.log(listId);
// _id of the searched item
var companyId = this._id;
console.log(companyId);
Meteor.call('addToList', listId, companyId, function (error, result) {
if (error) {
} else {
}
});
}
Method
Meteor.methods({
addToList: function (listId, companyId) {
check(listId, String);
check(companyId, String);
var add = Lists.update({
_id: listId,
companies: {$ne: companyId}
}, {
$addToSet: {companies: companyId},
$inc: {companyCount: 1}
});
return add;
}
});
Object of List
list = {
_id: listId,
name: nameOfList
companies: [
// _ids of added companies
0: 'addedCompanyId',
1: 'someOtherAddedCompanyId',
and so forth...
]
}
From here, I am trying to make a sub/pub that shows ONLY the companies that are added in list.companies
.
I have no idea on howā¦
I am thinking of something like this.
<template name = "list">
{{#each addedCompanies}}
something here
{{/each}}
</template>
Template.list.helpers({
addedCompanies: function () {
companies = this.companies;
return Clients.find(/*something here*/);
}
});
Everything Iāve written works so far. But I am lost in returning a cursor from an array of _id
s.