如何阻止闪烁的条件呈现?
问题描述:
我不确定这是Meteor问题还是通用问题,但我的应用中有以下代码。如何阻止闪烁的条件呈现?
<template name='admin'>
<div class='admin container-fluid noPadding'>
{{#if isInRole 'Admin'}}
<h3 class="homepageText">Server Statistics</h3>
{{> serverFacts}}
{{else}}
You don't belong here!
{{/if}}
</div>
当页面呈现我看到“你不属于这里!”,然后在“服务器统计”替换它一秒钟左右后。我的应用程序中的其他地方的问题始终与Blaze {{#if ...}}
有关。有没有办法阻止页面在浏览器中显示,直到渲染完成并解决?
答
这是反应式应用程序的通用问题 - 渲染通常发生在数据仍被推送到客户端时。通常的解决方案是使用微调器(例如:sacha:spin),直到基础订阅准备就绪。然后,在大火你结束了:
<template name='admin'>
{{#if loading}}
{{> spin}}
{{else}}
<div class='admin container-fluid noPadding'>
{{#if isInRole 'Admin'}}
<h3 class="homepageText">Server Statistics</h3>
{{> serverFacts}}
{{else}}
You don't belong here!
{{/if}}
{{/if}}
</div>
你需要一个帮手根据您的订阅来计算loading
。在由多个订阅支持的更复杂的布局中,您最终可能会同时拥有多个纺纱器。