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