路线非常简单:
App.Router.map(function() {
this.resource('users', {path: '/'}, function() {
this.resource('user', {path: '/user/:user_id'});
});
});
以及以下模板:
# application
.container= outlet
# users
.left
ul.users-list= each controller
li= link-to 'user' this
= fullName
.main
= outlet
# users/index
p please select user from the list
是否可以获得当前的应用状态?例如,知道usersIndexRoute
处于活动状态(空白状态)以不同地设置.main
样式是有用的。
我希望在应用程序视图中具有此状态,例如在.container
中绑定。
答案 0 :(得分:4)
重复@Panagiotis Panagi's回答,您只需将classForPath
属性绑定到应用程序视图,如下所示:
App.ApplicationView = Ember.View.extend({
classNames: ['app'], // Static classes here.
classNameBindings: ['classForPath'], // Your dynamic path here.
classForPath: function() {
var currentPath = this.get('controller.currentPath') || '';
currentPath = Ember.String.decamelize(currentPath);
// Note we prefix with a string 'current-path-' in case the route is
// an integer e.g., 404. CSS classes cannot start with numbers.
currentPath = 'current-path-' + currentPath.split('.').join('-');
return currentPath;
}.property('controller.currentPath')
});
答案 1 :(得分:2)
使用currentPath
的{{1}}获取当前路径路径并将其绑定到ApplicationController
类:
container
App.ApplicationView = Ember.View.extend({
classForPath: (function() {
var currentPath = this.get('controller.currentPath') || '';
currentPath = Ember.String.decamelize(currentPath);
currentPath = currentPath.split('.').join('-');
return currentPath;
}).property('controller.currentPath')
});