流星铁路由器 - 如何等待(使用加载模板)一个会话.get
Meteor Ironrouter - how to waiton (with a loading template) a Session.get?
我正在尝试使用一些变量(来自 Session.get())渲染一个"spotresult"模板。我花了很多时间在上面,但我没有找到答案......你能帮我吗?
https://git.geekli.st/balibou/hackaton_volant/tree/master/cerfvolantspatial
多谢!
//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'});
布局模板:
<template name="layout">
<div class="container">
{{> header}}
</div>
<div class="container mainyield">
{{> yield}}
</div>
</template>
加载模板:
<template name="loading">
{{>spinner}}
</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>
我认为问题出在这里,请替换为此代码。
Template.spot.helpers({
showSpinner:function(){
if(Session.get("windspeed7" === ''){
return true;
}else{
return false;
}
}
});
并将此助手添加到另一个助手中
{{#if showSpinner}}
{{else}}
{{>spinner}}
{{/if}}
这应该有效
相关文章:
- 当用$.getScript()加载脚本时,有一种方法可以从用$.get script()装载的脚本中调用父脚本中的函数
- Codeigniter JQuery在JQuery.get请求后动态加载视图中的数据
- JQuery AJAX - 如何使用方法 GET 调用刷新/重新加载页面
- 如何使用 GET 和 POST 语句而不使用 PHP/Laravel 重新加载页面
- $.get()加载的图像没有't显示
- 如何通过发送GET和POST的javascript重新加载页面,并附加附加参数
- 使用$.get-Jquery Mobile加载弹出窗口
- 如何在CasperJS脚本中通过get-int变量加载JSON
- XMLHttpRequest无法加载http://localhost:3000/get.
- 流星铁路由器 - 如何等待(使用加载模板)一个会话.get
- D3 JS - 在没有 HTTP Get 的情况下加载 JSON
- Tinymce 4 正在加载,但显示 tinymce.get 未定义
- 通过 GET URL 加载引导导航导航选项卡
- AngularJS服务,从$html.get返回预加载的数据或数据
- 从 $http.get 加载手风琴组使用 AngularJS 打开.
- 角度 - 在页面加载时触发$http.get
- Angularjs $http.get 调用在页面加载时出错
- jQuery onClick 通过 GET 传递变量到 URL 并加载该 URL
- 如何调用chrome.storage.sync.get并在页面加载时分配变量
- 在加载$http-get图像之前显示加载覆盖