Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js Ember路由器:如何在Ember 1.0-rc2的运行时添加路由?_Ember.js_Ember Router - Fatal编程技术网

Ember.js Ember路由器:如何在Ember 1.0-rc2的运行时添加路由?

Ember.js Ember路由器:如何在Ember 1.0-rc2的运行时添加路由?,ember.js,ember-router,Ember.js,Ember Router,在随Ember 1.0-rc2发货的新的Ember.Router中,是否可以在运行时添加路由?目前没有支持的方法。App.Router.map调用由该代码的第235-247行处理: 每次调用Router.map时,映射都会被覆盖,因为上次调用Router.map的回调不会持久化 编辑 不管是好是坏,我收到了一个拉入请求来改变行为,以允许对App.Router.map进行多个调用。我们看看会发生什么。你可以跟着这里 另一次编辑 我已经写了一个要点来做我的拉请求在userland中所做的事情。这将允

在随Ember 1.0-rc2发货的新的
Ember.Router
中,是否可以在运行时添加路由?

目前没有支持的方法。
App.Router.map
调用由该代码的第235-247行处理:

每次调用
Router.map
时,映射都会被覆盖,因为上次调用
Router.map
的回调不会持久化

编辑 不管是好是坏,我收到了一个拉入请求来改变行为,以允许对
App.Router.map
进行多个调用。我们看看会发生什么。你可以跟着这里

另一次编辑

我已经写了一个要点来做我的拉请求在userland中所做的事情。这将允许您在运行时映射路由。只需添加此代码,然后用我定义的方法替换对
App.Router.map
的调用

答案更改编辑


从这个拉取请求开始,您现在可以多次调用
map

我看到wmarbut的答案没有被接受,但(对我来说)是个好答案。看起来他的补丁正在进入灰烬版本,但在此之前,这是一些使用他的补丁的代码。(不要接受我的回答,我很高兴找到了这个答案。)我计划将它作为让内容驱动导航的解决方案的一部分。好问题,用户1517325和谢谢,wmarbut

  // was an all-in-one router map as Ember likes it
  // App.Router.map(function() {
  //   this.resource("foods", function(){
  //     this.route("index", {path: "/"});
  //   });
  //   this.route("fourOhFour", { path: "*:"});
  // });

  //wmarbut's workaround until his patch is applied
  App.map_routes = [];

  App.MapRoutes = function(routes) {
      App.map_routes.push(routes);
      return App.Router.map(function() {
        var route_lamda, _i, _len, _ref;
        _ref = App.map_routes;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          route_lamda = _ref[_i];
          route_lamda.call(this);
        }
        return true;
      });
  };

  //partial mapping
  App.MapRoutes(function() {
    this.resource("foods", function(){
    });
  });

  //some more mapping
  App.MapRoutes(function() {
    this.resource("foods", function(){
      this.route("index", {path: "/"});
    });
  });

  //even more mapping
  App.MapRoutes(function() {
    this.route("fourOhFour", { path: "*:"});
  });
//是安博喜欢的一个多功能路由器地图
//App.Router.map(函数(){
//这是一种资源(“食物”,功能(){
//路由(“索引”,{path:“/”});
//   });
//这个路径(“fourOhFour”,{path:*:“});
// });
//wmarbut的变通方法,直到应用补丁
App.map_routes=[];
App.MapRoutes=功能(路由){
应用程序。地图\路线。推送(路线);
返回App.Router.map(函数(){
var route_lamda,_i,_len,_ref;
_ref=App.map\u路线;
对于(_i=0,_len=_ref.length;_i<_len;_i++){
路线_lamda=_ref[_i];
路线_lamda.呼叫(本);
}
返回true;
});
};
//部分映射
App.MapRoutes(函数(){
这是一种资源(“食物”,功能(){
});
});
//更多的映射
App.MapRoutes(函数(){
这是一种资源(“食物”,功能(){
路由(“索引”,{path:“/”});
});
});
//更多映射
App.MapRoutes(函数(){
这个路径(“fourOhFour”,{path:*:“});
});

在最新版本的ember.jsrc7中,它将功能添加到了
Router.map
中,允许多次调用它,而不会覆盖map。这将允许在运行时添加路由


希望有帮助。

查看我刚才添加的编辑,它为您提供了一个解决方案,您可以访问并使用它
  // was an all-in-one router map as Ember likes it
  // App.Router.map(function() {
  //   this.resource("foods", function(){
  //     this.route("index", {path: "/"});
  //   });
  //   this.route("fourOhFour", { path: "*:"});
  // });

  //wmarbut's workaround until his patch is applied
  App.map_routes = [];

  App.MapRoutes = function(routes) {
      App.map_routes.push(routes);
      return App.Router.map(function() {
        var route_lamda, _i, _len, _ref;
        _ref = App.map_routes;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          route_lamda = _ref[_i];
          route_lamda.call(this);
        }
        return true;
      });
  };

  //partial mapping
  App.MapRoutes(function() {
    this.resource("foods", function(){
    });
  });

  //some more mapping
  App.MapRoutes(function() {
    this.resource("foods", function(){
      this.route("index", {path: "/"});
    });
  });

  //even more mapping
  App.MapRoutes(function() {
    this.route("fourOhFour", { path: "*:"});
  });