0

如果选择更改,则以下控制器会更新表格。这样可行。但是后退按钮会返回到最后一条路线,而不是最后的选择(在这种情况下,这是预期的行为)。

但我更希望后退按钮带我回到最后一个选择。到目前为止,我已经尝试创建一个新路由并从 selectionChanged 调用 transitionTo 并将 this.selection.name 设置为新路由。但这不起作用(不能调用未定义的方法“transitionTo”)。

所以问题是:在浏览器位置反映选择更改的推荐方法是什么?

NewApp.GridController = Em.Controller.extend({
    content: [],      // bound to Ember.Select view  
    selection: null,  // bound to Ember.Select view
    tableContent: [],

    selectionChanged: function () {
        var that = this;
        if (this.selection) {
            $.getJSON("api/v1/lists/" + this.selection.name + "/prices", function (content) {
                that.set('tableContent', content);
                NewApp.router.root.prototype.switchRoute();
            });
        }
    }.observes('selection'),

    initController: function () {
        var that = this;
        $.getJSON("api/v1/lists/all", function (content) {
            that.set('content', content);
            that.set('selection', content.get(0));
        });
    }

});

路由器看起来像这样:

NewApp.Router = Ember.Router.extend({
  enableLogging: true,
  location: 'hash',

  root: Em.Route.extend({

    show3: Ember.Route.transitionTo('root.third'),

    switchRoute: Ember.Route.transitionTo('root.listname'),

    index: Em.Route.extend({
      route: '/',
      redirectsTo: 'main'
    }),

    main: Em.Route.extend({

      route: 'app',

      connectOutlets: function (router, context) {
        router.get('helloController').initController();
        return router.get('applicationController').connectOutlet({
          name: 'hello'
        });

      }

    }),

    third: Em.Route.extend({

      route: 'third',

      connectOutlets: function (router, context) {
        router.get('gridController').initController();
        return router.get('applicationController').connectOutlet({
          name: 'grid'
        });

      }

    }),

    listname: Em.Route.extend({
      route: 'routeName' // static, just for testing
    })

  })

});
4

0 回答 0