0

我有一个应用程序,我想在其中为用户呈现信息栏,application.hbs如下所示:

{{render "userInfoBar"}}

{{outlet}}

<footer id="footer-info">copyright by me</footer>

我创建了UserInfoBarControllerUserInfoBarView类,它们都派生自相应的 Ember 类,并从init()两者的函数中写入日志输出。现在,UserInfoBarViewsinit()方法被调用了两次!第一次在的方法之前调用它,在初始化控制器之后再次调用它。因此我无法为 设置 a ,因为第一个初始化是在之前插入的......init()UserInfoBarControllerelementIdUserInfoBarViewUserInfoBarView

这是生成的日志输出:

UserInfoBarView:: init() called... 
UserInfoBarController:: init() called...
UserInfoBarView:: init() called... 
UserInfoBarView:: inserted to DOM...ember195
UserInfoBarView:: inserted to DOM...ember198 

这是控制器:

App.UserInfoBarController = Ember.ObjectController.extend({
  init: function() {
    console.debug('UserInfoBarController:: init() called...');
  }
});

这是视图:

App.UserInfoBarView = Ember.View.extend({
  tagName: 'div',
  classes: ['container', 'centered'],

  init: function() {
    console..debug('UserInfoBarView:: init() called...');
  },

  didInsertElement: function() {
    console.debug('UserInfoBarView:: inserted to DOM...' + this.$().attr('id'));
  }
});

编辑:

这是userInfoBar模板:

{{#view App.UserInfoBarView}}
  <div id="userInfoBarDetails1">
  </div>
  <div id="userInfoBarDetails2">
  </div>  
  <div id="userInfoBarDetails3">
    {{controller.fullname}}
  </div>
{{/view}}

为什么UserInfoBarView会渲染两次?

4

0 回答 0