【发布时间】:2015-10-03 16:40:14
【问题描述】:
我现在正在做一个清单。
用户将能够搜索然后单击搜索的项目以将相应的 id 添加到他们的列表中。
这是我编写的以下代码。
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 {
}
});
}
方法
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;
}
});
列表对象
list = {
_id: listId,
name: nameOfList
companies: [
// _ids of added companies
0: 'addedCompanyId',
1: 'someOtherAddedCompanyId',
and so forth...
]
}
从这里开始,我正在尝试创建一个子/pub,仅显示在 list.companies 中添加的公司。
我不知道如何..
我正在考虑这样的事情。
<template name = "list">
{{#each addedCompanies}}
something here
{{/each}}
</template>
Template.list.helpers({
addedCompanies: function () {
companies = this.companies;
return Clients.find(/*something here*/);
}
});
到目前为止,我所写的所有内容都有效。但是我在从_ids 的数组中返回一个游标时迷失了。
更新
简单地说,我可以从多个 _id 中返回一个游标作为查询吗??
【问题讨论】:
标签: meteor publish-subscribe meteor-helper