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));
所以我的标题不属于特定的 url,需要一直在那里。
我有相关的 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')
在我的 URL 中,当我沿着嵌套路线 /clients/someClient/claims/1/1 行驶时,
当我到达 ClaimController 时。我在声明模板中有一个部分需要访问标头控制器的“clientClaimBillText”方法。
在我的 ClaimController 中,我指定了“需求”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>
部分渲染正确。我遇到的问题是标题的模板似乎失去了它的状态。就像它吹走了用户对象。所有绑定的属性都重新呈现,但没有设置它的用户对象。它就像原来的 Nucleus.User.find(1) 已经消失了。
希望它的一些微不足道的我失踪了。