代码之家  ›  专栏  ›  技术社区  ›  Toran Billups

如何使用ember.js从url更改启动模式?

  •  1
  • Toran Billups  · 技术社区  · 12 年前

    我使用ApplicationRoute获得了一个有效的“从事件启动模式”,但如果可能的话,我想跟踪url中的模式更改。

    App.ApplicationRoute = Ember.Route.extend({
      actions: {
        modal: function() {
          view = Ember.View.create({
            templateName: "modal",
            controller: this.controller,
            content: []
          }).appendTo('body');
        }
      }
    });
    

    如果我更改了url,我如何触发模态来显示给定的上下文(使用url参数来构建它)?

    1 回复  |  直到 12 年前
        1
  •  1
  •   Matthew Blancarte    12 年前

    根据您希望此行为的集中程度,您可以向应用程序控制器添加路径观察器:

    App.ApplicationController = Ember.Controller.extend({
      //...
      currentPathDidChange: function () {
        switch(this.get('currentPath')){
          case 'foo-route.index':
            //trigger modal change
            break;
        }
      }.observes('currentPath')
      //...
    });