1
我有两个出版物。流星的出版物/订阅不能按预期工作
第一个酒吧执行搜索。特别是This search。
/* publications.js */
Meteor.publish('patients.appointments.search', function (search) {
check(search, Match.OneOf(String, null, undefined));
var query = {},
projection = {
limit: 10,
sort: { 'profile.surname': 1 } };
if (search) {
var regex = new RegExp(search, 'i');
query = {
$or: [
{'profile.first_name': regex},
{'profile.middle_name': regex},
{'profile.surname': regex}
]
};
projection.limit = 20;
}
return Patients.find(query, projection);
});
第二个基本返回一些领域
/* publications.js */
Meteor.publish('patients.appointments', function() {
return Patients.find({}, {fields: {'profile.first_name': 1,
'profile.middle_name': 1,
'profile.surname': 1});
});
我已经订阅每个发布,像这样:
/* appointments.js */
Template.appointmentNewPatientSearch.onCreated(function() {
var template = Template.instance();
template.searchQuery = new ReactiveVar();
template.searching = new ReactiveVar(false);
template.autorun(function() {
template.subscribe('patients.appointments.search', template.searchQuery.get(), function() {
setTimeout(function() {
template.searching.set(false);
}, 300);
});
});
});
Template.appointmentNewPatientName.onCreated(function() {
this.subscribe('patients.appointments');
});
因此,这里是我的问题:当我使用第二预订(到appointments.patients
),第一个不起作用。当我评论第二次订阅时,第一次订阅会再次生效。我不确定我在这里做错了什么。