出于报告目的,我想将一些元数据与 Ember 路由相关联,并且希望按如下方式进行:
this.route('list', { path: '/list', description: 'Master List' });
然后访问此
description
来自路线本身或其他地方的属性(property),例如 didTransition
卡在应用路由器上。我已经查看了 Router 和 Route 的源代码,但不能说我真的理解它,当然还不足以理解如何检索以这种方式指定的自定义属性。我看到有一个名为 DSL 的对象,显然是 this
的this.route
在 map
中指定Router
上的方法,但看不到如何从这里到那里。来自 Ember.Route
的子类,我看到名为 this.router
的属性, 和 this.router.router
,但不清楚这些指向什么。或者,如果这允许我做我想做的事,以下内容也可以工作:
this.route('list', { path: '/list' }, function() {
this.description = "Master List";
});
我可以将自定义属性与
Router#map
中指定的路由关联吗? ,如果是这样怎么办?
最佳答案
当在路由器中定义路由时,似乎没有一种优雅的方式来设置有关路由的元数据,但也许可以在您的应用程序 Controller 中尝试这个丑陋的解决方案:
currentPathChange: function () {
switch(this.get('currentPath')){
case 'test.index':
console.log('test.index is the foo!');
break;
case 'test.new':
console.log('test.new is the bar!');
break;
}
}.observes('currentPath')
JSBin DEMO
关于ember.js - 从 Ember 路由添加和检索元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30403151/