0
Meteor.publish('singleDocument', function(documentId) {
return Documents.find(documentId);
});
this.route("documentPage", {
path: "/documents/:_id",
waitOn: function() {
return Meteor.subscribe("singleDocument", this.params._id);
},
data: function() {
return Documents.findOne(this.params._id);
}
});
Template.documentPage.rendered = function() {
Tracker.autorun(function() {
console.log(this.content);
});
};
正如你可以看到我已经设置的一切,我等待的收集与waitOn
。但console.log(this.content);
仍然会返回undefined
,好像该集合尚未加载。
可能是什么问题?
你说得对,它的工作。谢谢。那么在Tracker.autorun中没有办法使用它?如果我想在每次收集更新时要运行的函数中使用它, – alexchenco 2015-02-11 03:34:29
@alexchenco,我认为你可以使用Template.currentData。看到我更新的答案。 – 2015-02-11 07:28:50