[英]Meteor Ironrouter - how to waiton (with a loading template) a Session.get?
I'm trying to render a 'spotresult' template with some variable (from Session.get()). 我正在尝试使用一些变量(来自Session.get())呈现一个“ spotresult”模板。 I've spent a lot of time on it but I didn't find an answer ... Could you help me please ? 我已经花了很多时间,但是我没有找到答案……您能帮我吗?
https://git.geekli.st/balibou/hackaton_volant/tree/master/cerfvolantspatial https://git.geekli.st/balibou/hackaton_volant/tree/master/cerfvolantspatial
Thanks a lot ! 非常感谢 !
//router.js
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
Router.route('/', {name: 'spot'});
// 1.Normal rendering
//Router.route('/spotresult',{name: 'spotresult'});
----------------------------------------------------------------------------- -------------------------------------------------- ---------------------------
// 2. First attempt
//Router.route('/spotresult', {
// name: 'spotresult',
// action: function () {
// if (this.ready())
// this.render();
// else
// this.render('loading');
// }
//});
//3. Second attempt
//var waitingSession = function() {
// if (!this.ready()) {
// this.render(this.loadingTemplate);
// } else {
// this.next();
// }
//}
//
//Router.onBeforeAction(waitingSession, {only: 'spotresult'});
Layout template: 布局模板:
<template name="layout">
<div class="container">
{{> header}}
</div>
<div class="container mainyield">
{{> yield}}
</div>
</template>
Loading template: 加载模板:
<template name="loading">
{{>spinner}}
</template>
Spot template: 现货模板:
<template name="spot">
<div class="spot">
{{#if currentUser}}
<p class="text-center">Bonjour, bienvenue sur votre profil</p>
{{else}}
<h4 class="text-center">Bonjour, pour connaître la vitesse du vent, remplissez le champs ci-dessous !</h4>
<form role="form" class="new-spot">
<div class="form-group">
<label for="email">Spot :</label>
<input name="lieu" type="text" class="form-control" id="lieu" placeholder="Entrez un lieu">
</div>
<button type="submit" class="btn btn-default">Valider</button>
</form>
{{#if windspeed7}}
{{>spotresult}}
{{/if}}
{{/if}}
</div>
</template>
i think the problem is here, replace with this code. 我认为问题就在这里,用此代码替换。
Template.spot.helpers({
showSpinner:function(){
if(Session.get("windspeed7" === ''){
return true;
}else{
return false;
}
}
});
And add this helper inside the other helper 并将此助手添加到另一个助手中
{{#if showSpinner}}
{{else}}
{{>spinner}}
{{/if}}
This should work 这应该工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.