Ember“needs”导致以前的控制器方法失败

时间:2013-04-30 17:43:23

标签: ember.js

Ember:v1.0.0-rc.3-112-g3ec3711
EmberData:最后提交:f8cb714(2013-04-28 07:24:47 -0700)

我正在与交叉控制器通信的“需求”api进行斗争。

我在Application.Route中定义了顶级控制器,如此

this.controllerFor('header').set('model', Nucleus.User.find(1));

所以我的标题不属于特定网址,需要一直在那里。

我有相关的HeaderController和一些方法。

  userName: function () {
    return this.get('firstName') + " " + this.get('lastName');
  }.property('firstName', 'lastName'),

  clientLogo: function () {
    return Nucleus.localDomain + 'Content/images/logos/logo_' + this.get('currentClient') + '.png';
  }.property('currentClient'),

  clientClaimBillText: function () {
    if (this.get('clientType') === "PropertyAndCasualty") {
      return "Bill";
    }
    return "Claim";
  }.property('clientType')

在我的网址中,我沿着嵌套路线/客户/ someClient / claim / 1/1行进,

当我到达ClaimController时。我在声明模板中有一部分需要访问标头控制器的“clientClaimBillText”方法。

在我的ClaimController中,我指定了“needs”api

Nucleus.ClaimController = Ember.ObjectController.extend({
  needs: ['header']

});

在我的索赔模板中,我称之为部分。我需要访问HeaderController属性的地方。

<script type="text/x-handlebars" data-template-name="_claim_header">
  <div id="page_header" class="silver_gradient">
        <div class="sub_nav_content">
            <div class="sub_nav_left">
                <label class="page_title">{{controllers.header.clientClaimBillText}} Action</label>
            </div>
            <div class="sub_nav_right">

            </div>
        </div>
    </div>
</script>

部分呈现正确。我遇到的问题是标题的模板似乎松散了它的状态。就像它吹走了UserObject。所有绑定属性都会重新呈现,但没有设置的用户对象。它就像原来的Nucleus.User.find(1)一样消失了。

希望它缺少一些微不足道的东西。

1 个答案:

答案 0 :(得分:0)

我没有看到任何明显的东西。听起来你可能有两个“标题”控制器实例。它们是同一个对象ID吗?

// in Application.Route
controller = this.controllerFor('header');
controller.set('model', Nucleus.User.find(1));
console.log ('from app route header controller is: ', controller.toString());

// in your template
<pre>Header controller is; {{controllers.header}}</pre>