[英]What is wrong with this Ember.js handlebars if statement?
Hi i have an ember app with a handlebars if else statement that always shows the if part and never the else 嗨我有一个带把手的余烬应用程序if else语句总是显示if部分而不是其他
I have read everything i can in the ember documentation here and here and searched the net countless times:( 我已经阅读了这里和这里的余烬文档中的所有内容,并在网上无数次搜索:(
The code for my controller and template appear below i think the problem may have something to do with my session initializer that my controller references not being loaded before my controller? 我的控制器和模板的代码显示在下面我认为问题可能与我的会话初始化程序有关,我的控制器引用没有在我的控制器之前加载?
I have read here and here and many other places i have forgotten:( trying to learn how to get my initializer loaded before my controller 我已经阅读了这里和这里以及我忘记的许多其他地方:(试图学习如何在我的控制器之前加载初始化器
Below is the code for my application controller and my application template 下面是我的应用程序控制器和我的应用程序模板的代码
<nav role="navigation" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" data-target="#navbarCollapse" data-toggle="collapse" class="navbar-toggle">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
{{#link-to "index" class="navbar-brand"}}Hide The Word{{/link-to}}
</div>
<!-- Collection of nav links and other content for toggling -->
<div id="navbarCollapse" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
{{#if 'registered'}}
<li>{{#link-to "user" userId}}{{user}}{{/link-to}}</li>
<li>{{#link-to "logout"}}Logout{{/link-to}}</li>
{{else}}
<li>{{#link-to "login" class = "navbar-right"}}{{user}}{{/link-to}}</li>
<li>{{#link-to "login" class = "navbar-right"}}Sign In{{/link-to}}</li>
{{/if}}
<button{{action 'test'}}>test</button>
</ul>
</div>
</div>
</nav>
{{outlet}}
application.js 的application.js
import Ember from 'ember';
export default Ember.Controller.extend({
user:function(){
if(this.get('session').authed){
var provider = this.get('session').authData.auth.provider,
name = this.get('session').authData[provider].displayName;
return name;
}else{
return 'Hi Guest'
}
}.property(),
registered:function(){
if(this.get('session').authed){
return true;
}
else{
return false;
}
}.property(),
});
Your if statement's value is quoted. 引用了您的if语句的值。
{{#if 'registered'}}
Should be: 应该:
{{#if registered}}
I think that'll fix it. 我想那会解决它。 With the quotes, it'll always evaluate as true.
使用引号,它将始终评估为真。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.