Ember.js - 嵌套路由上的索引重复/退出时不销毁

时间:2014-02-14 23:18:57

标签: javascript ember.js

有一个问题,即ember在退出时没有销毁索引。

控制器/路线:

App.AccountRoute = Ember.Route.extend({
    activate: function () {
        //Doing some stuff with login state here. Not important.
    }
});

App.AccountController = Ember.Controller.extend({
    needs: ['application'], //dependency
    account: Ember.computed.alias('controllers.application.accountData'),
    states: Ember.computed.alias('controllers.application.states'),
    userToken: Ember.computed.alias('controllers.application.userToken'),

    tabs: [{'pinned': true, 'name': { 'nestedLink': 'account.index', long: 'Account Overview' }}, {'name': { 'nestedLink': 'account.edit-profile', long: 'Edit Your Company Profile' }}, {'name': { 'nestedLink': 'account.edit-listings', long: 'Edit Your Company Listings' }}, {'name': { 'nestedLink': 'account.edit-payment-methods', long: 'Edit Your Saved Payment Methods' }}, {'name': { 'nestedLink': 'account.view-orders', long: 'View Orders' }}],
});

App.AccountIndexController = Ember.Controller.extend({
    needs: ['account']
});

这是路由器:

App.Router.map(function () {
        //...
    this.resource('account', function() {
        this.route('edit-profile');
        this.route('edit-listings');
        this.route('edit-payment-methods');
        this.route('view-orders');
    });
});

帐户模板设置如下,其中包含指向每个嵌套路线的链接,例如:{{#linkTo account.index}}{{/linkTo}} {{#linkTo account.view-orders}}{{/linkTo}}

<script type="text/x-handlebars" data-template-name="account">
            <h2>Account for {{account.name.company}}</h2>
            <hr />
            <div class="row">
                <div class="col-md-2 account-sidebar">
                    <ul class="list-group">
                        {{#each tabs}}
                            {{#if pinned}}
                                {{#linkTo name.nestedLink class="list-group-item pinned-item"}}
                                    {{name.long}}
                                {{/linkTo}}
                            {{else}}
                                {{#linkTo name.nestedLink class="list-group-item"}}
                                    {{name.long}}   
                                {{/linkTo}}
                            {{/if}}
                        {{else}}
                            <p class="text-danger">There are no options for your account.</p>
                        {{/each}}
                    </ul>
                </div>
                <div class="col-md-10 account-content">
                    {{outlet}}
                </div>
            </div>
        </script>

        <script type="text/x-handlebars" data-template-name="account/index">
            <h3>Account Overview</h3>
        </script>

在概览(索引)选项卡和嵌套路由之间来回切换会导致:ember duplication

1 个答案:

答案 0 :(得分:3)

您在&#34;帐户/索引&#34;中错过了结束</div>。模板。它应该是

<script type="text/x-handlebars" data-template-name="account/index">
   <h3>Account Overview</h3>
   <hr />
   <div class="row">
      <div class="col-md-6">
         <h4>Account Created:</h4>
         <p class="text-muted"></p>
      </div>

      <div class="col-md-6">
         <h4>Account Address:</h4>
         </p>
      </div>
   </div>
</script>

请参阅http://emberjs.jsbin.com/novib/3/