这是代码:
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,好像还没有加载集合一样。
有什么问题吗?
发布于 2015-02-10 16:53:55
自动运行中的this不引用用于呈现模板的数据上下文。在呈现的函数中,在autorun函数之外(您根本不需要使用autorun ),您可以使用this.data引用用于呈现模板的数据上下文,因此尝试如下:
Template.documentPage.rendered = function() {
console.log(this.data);
};根据下面的评论更新:
您应该能够使用Template.currentData侦听数据上下文中的更改:
Template.documentPage.rendered = function() {
Tracker.autorun(function(){
console.log(Template.currentData())
})
};https://stackoverflow.com/questions/28436333
复制相似问题