简体   繁体   English

烬模板中的transitiontoroute()之后父模板未更新

[英]parent template is not updating after transitiontoroute() in ember js

  1. List item 项目清单

I have login controller . 我有登录控制器。 After login successful I am calling controller.transitionToRoute('patients.index') which is my dashboard. 成功登录后,我正在调用controller.transitionToRoute('patients.index'),这是我的仪表板。 Page gets redered but my header menu is not updating . 页面变红了,但是我的标题菜单没有更新。 If I try to refresh page by hitting F5 then my header gets updated. 如果我尝试通过按F5刷新页面,则标题会更新。

Thanks in advance. 提前致谢。

My controller: 我的控制器:

export default Ember.Controller.extend({
    login: Ember.inject.service('testservice'),
    actions: {
    authenticate: function() { 
    var controller=this; 
         controller.set('login').currentUser=false;
         controller.transitionToRoute('dashboard.index');
       },
    }

});

Dashboard route : 资讯主页路线:

export default Ember.Route.extend({
  authManager: Ember.inject.service('testservice'),
     renderTemplate: function() {
        this.render({
             outlet: 'master',
        });
     },
});

application.hbs handlbar: application.hbs把手:

<header id="main">

{{#link-to 'index'}}<img id="logo" src="assets/logo.png"/>{{/link-to}}

<ul id="user">
  <li><a id="user-icon"></a>
    <ul>
      {{#if isUser}}
        <li>{{#link-to 'account.edit'}}Account{{/link-to}}</li>
        <li>{{#link-to 'account.invitation'}}Invite{{/link-to}}</li>

        <li><a {{action 'logout'}}>Logout</a></li>
      {{else}}
        <li><a {{action 'Userlogin'}}>Login</a></li>
      <li>{{isUser}}</li>

      {{/if}}

    </ul>
  </li>
 </ul>

</div>
</header>

<div class="container">
  {{outlet}}
</div>

application controller: 应用控制器:

export default Ember.Controller.extend({
    login: Ember.inject.service('testservice'),
    isUser:function() {
       return this.get('login').currentUser;
    }.property('login'),
});

controller.set('login').currentUser=false; as well as return this.get('login').currentUser; 以及return this.get('login').currentUser; is wrong! 是错的!

First what is controller ? 首先, controller是什么? Probably you want to use Ember.set(this, 'login.currentUser' true) , or this.set('login.currentUser', true) , or this.get('login').set('currentUser', true) . 可能您想使用Ember.set(this, 'login.currentUser' true)this.set('login.currentUser', true)this.set('login.currentUser', true) this.get('login').set('currentUser', true)

For the get its the same. 对于获得相同的。 Usually never do ...get(...).something ! 通常不做...get(...).something Just do this.get('login.currentUser') or Ember.get('login.currentUser') . 只需执行this.get('login.currentUser')Ember.get('login.currentUser')


Btw you can rewrite 顺便说一句,你可以重写

isUser:function() {
   return this.get('login').currentUser;
}.property('login'),

with

isUser: Ember.computed.alias('login.currentUser'),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM