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
),第一個不起作用。當我評論第二次訂閱時,第一次訂閱會再次生效。我不確定我在這裏做錯了什麼。