【发布时间】:2023-03-09 12:52:01
【问题描述】:
我试图从 iron 路由器 中获取两个变量,以便我可以在我的模板中调用它们,例如 {{user.telephone}} 和 {{pic.profilepic}}。
我在路由器中的代码如下。 (不工作!)
Router.route('/profile/:_id', {
name: 'profile',
template: 'profile',
data:function(){
return {
user:Info.findOne({_id:this.params._id}),
pic: Profilepics.findOne({_id:this.params._id})
};
},
subscriptions: function(){
return {
Meteor.subscribe("userInfo"),
Meteor.subscribe( "profilepic");
},
action:function (){
if (this.ready()){
this.render();
}else {
this.render('loading');
}
}
});
我只能用下面的代码做一个变量。即得到{{user.telephone}}。任何人都可以帮助我获得两个变量而不是一个变量吗?
enterRouter.route('/profile/:_id', {
name: 'profile',
template: 'profile',
data:function(){
return {
user:Info.findOne({_id:this.params._id})
};
},
subscriptions: function(){
return Meteor.subscribe("userInfo")
},
action:function (){
if (this.ready()){
this.render();
}else {
this.render('loading');
}
}
});
【问题讨论】:
-
尝试以数组形式返回多个订阅
return [ Meteor.subscribe("userInfo"), Meteor.subscribe( "profilepic") ]; -
您确定这两个集合具有相同的
_id吗?Profilepics可能有 diff id。 -
是的。100% 确定
标签: meteor iron-router meteor-blaze