我是这个框架的新手。我想使用流量路由器,因为它是被动的。在此之前,我正在使用铁路由器。有人告诉我如何将代码更改为流路由器,因为流路由器没有waitOn概念和onBeforeAction(由triggersEnter取代)。你的帮助和善意真的很感激。
router.js
Router.route('/EditLokasi/:_id', {
name: 'EditLokasi',
template: 'EditLokasi',
onBeforeAction: function(){
var lokasiID = Lokasi.findOne({_id: this.params._id});
this.render('EditLokasi',{data: lokasiID});
},
waitOn: function(){
if(Meteor.userId()){
var userid = Meteor.user().username;
return [ Meteor.subscribe('profiles', userid), Meteor.subscribe('login') ];
}
}
});
EditLokasi.js
Template.EditLokasi.helpers({
lokasi: function(){
return Lokasi.find({data:lokasiID});
}
});
答案 0 :(得分:1)
您可以使用subscriptions
至subscribe,然后在模板上检查数据是ready到subReady
FlowRouter.route('/login', {
name: 'login',
subscriptions: function() {
var userid = Meteor.user().username;
this.register('subscribe-to-profile', Meteor.subscribe('profiles', userid));
// do it the same for other subscribe
},
action(params) {
var lokasiID = Lokasi.findOne({_id: this.params._id});
BlazeLayout.render('EditLokasi', {data: lokasiID});
}
});
在您的模板上
<template name="EditLokasi">
{{# if helper_checkSubReady}}
......
{{else}}
loading....
{{/if}}
</template>
helper_checkSubReady
是帮助检查订阅是否准备就绪(请查看我上面提到的链接)