Using this.added in Meteor

感情迁移 提交于 2019-12-25 04:21:02

问题


I'm trying to transform a publication, and this is my code:

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();

});

When I console.log(name), I can see the name in full but I'm not quite sure how to use this.added to add the new data. How do I go about this? And if I do enter this new data, will it overwrite the older data?

If there's a better way to achieve this, I'd also like to know.


回答1:


I believe what your code will do is to publish one, static set of appointments, and that should work. It cannot overwrite anything because it is creating something new (a new publication).

So as such I don't see anything wrong with your code. But if you are after a reactive publication that changes then Appointments changes, then you will need to use observe or observeChanges instead of .forEach -- and then also start using this.changed, rather than only added (unless things never change), and this.removed.



来源:https://stackoverflow.com/questions/39175965/using-this-added-in-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!