MeteorJS包装异步在铁路由器内不起作用
MeteorJS wrapasync not working inside iron router
我想检查用户是否达到了某个级别,并根据该级别进行路由。但这不会等待包装异步返回。如何实现这一点?
路由器.js
var getLevelAsync = function (userID, callback) {
Meteor.call('getLevel', Meteor.userId(), function (err, data) {
callback(null, data['level']);
})
}
var getLevel = Meteor.wrapAsync(getLevelAsync);
Router.route('/verifyData', function(){
var level = getLevel(Meteor.userId());
if(level < 3) this.render('somepage');
else this.render('another page');
})
服务器/方法.js
getLevel: function (userID) {
return Meteor.users.findOne({_id: userID});
}
Meteor.wrapAsync
围绕一个函数包装了一个未来,这只能在服务器上完成。您也不需要 Meteor 方法来实现您正在尝试执行的操作,您可以简单地呈现相同的页面,但根据当前用户呈现不同的上下文。
{{#with currentUser}}
{{#if aboveLevelThree}}
<h1>Congrats! You're in the special club!</h1>
{{else}}
<h3>Sorry mate, get a better score to advance</h3>
{{/if}}
{{/with}}
您的模板帮助程序如下所示:
Template['someTemplate'].helpers({
aboveLevelThree: function () {
return this.level > 3;
}
});
相关文章:
- UI 路由器参数 URL 不起作用,只是重定向到 /
- Angular 1.3+ui路由器+生成器ng poly嵌入嵌套(?)视图不起作用
- 角度 UI 路由器嵌套视图不起作用
- AngularJS和UI路由器:为什么$state.go()和$location.path()在交互式控制台中不起作用
- AngularJS路由器代码不起作用
- MeteorJS包装异步在铁路由器内不起作用
- 我的 ui 路由器链接不起作用,角度
- 流星模板助手在使用铁路由器后不起作用
- 反应路由器 v2.0 浏览器历史记录不起作用
- UI路由器状态的多个视图不起作用.未报告错误
- react路由器尾部斜线不起作用
- 主路由器在路由“”的末尾附加一个#"导致dom中引用锚点在Backbone/Require应用程序中不起作用
- Angular ui路由器在服务中保存到状态名称不起作用
- Angular ui路由器-重定向不'根本不起作用
- 反应路由器是活动方法不起作用
- 角度 UI 路由器 - 状态查询字符串参数不起作用
- 基本的React路由器示例不起作用
- Angular UI路由器使用go函数在状态之间传递数据不起作用
- Angularjs的嵌套路由器不起作用
- ExpressJS >路由器中间件>通过重定向传递变量 req.foo 不起作用