在 Meteor 中使用 this.added
Using this.added in Meteor
我正在尝试转换出版物,这是我的代码:
Meteor.publish('appointments.waiting', function () {
var self = this,
count = 0;
Appointments.find().forEach(function (appointment) {
var patients = Patients.find({_id: appointment.patient_id}).fetch();
var first_name = patients[count].profile.first_name,
middle_name = patients[count].profile.middle_name,
surname = patients[count].profile.surname,
name = surname + ', ' + first_name + ' ' + middle_name;
self.added('appointments', appointment.names, name);
});
self.ready();
});
当我 console.log(name)
时,我可以看到完整的名称,但我不太确定如何使用 this.added
添加新数据。我该怎么做?如果我输入这个新数据,它会覆盖旧数据吗?
如果有更好的实现方法,我也想知道
我相信您的代码将执行的是发布一组静态约会,这应该会起作用。它无法覆盖任何内容,因为它正在创建新内容(新出版物)。
因此,我没有发现您的代码有任何问题。但是如果你是在一个反应性的出版物之后改变然后 Appointments
改变,那么你将需要使用 observe
或 observeChanges
而不是 .forEach
- 然后也开始使用 this.changed
,而不只是添加(除非事情永远不会改变),以及 this.removed
.
我正在尝试转换出版物,这是我的代码:
Meteor.publish('appointments.waiting', function () {
var self = this,
count = 0;
Appointments.find().forEach(function (appointment) {
var patients = Patients.find({_id: appointment.patient_id}).fetch();
var first_name = patients[count].profile.first_name,
middle_name = patients[count].profile.middle_name,
surname = patients[count].profile.surname,
name = surname + ', ' + first_name + ' ' + middle_name;
self.added('appointments', appointment.names, name);
});
self.ready();
});
当我 console.log(name)
时,我可以看到完整的名称,但我不太确定如何使用 this.added
添加新数据。我该怎么做?如果我输入这个新数据,它会覆盖旧数据吗?
如果有更好的实现方法,我也想知道
我相信您的代码将执行的是发布一组静态约会,这应该会起作用。它无法覆盖任何内容,因为它正在创建新内容(新出版物)。
因此,我没有发现您的代码有任何问题。但是如果你是在一个反应性的出版物之后改变然后 Appointments
改变,那么你将需要使用 observe
或 observeChanges
而不是 .forEach
- 然后也开始使用 this.changed
,而不只是添加(除非事情永远不会改变),以及 this.removed
.