我在我的Ember.js应用程序中使用Twitter Bootstrap进行导航.Bootstrap active在li包含导航链接的标记上使用类,而不是active在链接本身上设置类.
Ember.js的新linkTo助手将active在链接上设置一个类,但(据我所见)并不提供任何挂钩到该属性.
现在,我正在使用这种丑陋的方法:
{{#linkTo "inbox" tagName="li"}}
<a {{bindAttr href="view.href"}}>Inbox</a>
{{/linkTo}}
Run Code Online (Sandbox Code Playgroud)
这将输出:
<li class="active" href="/inbox"><a href="/inbox">Inbox</a></li>
Run Code Online (Sandbox Code Playgroud)
这是我想要的,但不是有效的HTML.
我还尝试active从父视图绑定到生成的LinkView 属性,但如果这样做,父视图将在插入之前呈现两次,从而触发错误.
除了手动重新创建linkTo助手内部使用的逻辑以将active类分配给链接之外,还有更好的方法来实现这种效果吗?
在Ember中,将属性定义为另一个属性(或另一个对象的属性)的计算别名Ember.computed.alias('otherProperty')似乎与将其定义为使用该属性的绑定具有基本相同的结果propertyNameBinding: 'otherProperty'.
我查看了源代码和文档,但我找不到任何理由为什么一个优先于另一个.显然模板使用绑定,这很好,但对于例如控制器中的属性,或者在视图上引用控制器的属性,是否有区别?
我无法弄清楚使用新的Ember路由器处理模态状态/视图的正确方法.更一般地说,如何处理可以进入和退出而不影响"主"状态(URL)的状态?
例如,无论当前叶状态如何,始终可用的"新消息"按钮.单击"新消息"应在当前视图上打开新消息模式,而不会影响URL.
目前,我正在使用这样的方法:
路线:
App.Router.map(function() {
this.route('inbox');
this.route('archive');
});
App.IndexRoute = Em.Route.extend({
...
events: {
newMessage: function() {
this.render('new_message', { into: 'application', outlet: 'modalView' });
},
// Clicking 'Save' or 'Cancel' in the new message modal triggers this event to remove the view:
hideModal: function() {
// BAD - using private API
this.router._lookupActiveView('application').disconnectOutlet('modalView');
}
}
});
App.InboxRoute = Em.Route.extend({
...
renderTemplate: function(controller, model) {
// BAD - need to specify the application template, instead of using default implementation …Run Code Online (Sandbox Code Playgroud) 最近,更新了Ember.js,以便actions在路径/控制器/视图上的对象中定义操作事件处理程序.因此,事件处理程序不再是原型上的常规方法.
如果使用子类(例如)控制器extend,是否仍然可以覆盖然后调用超类的处理程序?
只是打电话_super不起作用:
FormController = Em.ObjectController.extend({
actions: {
submit: function() { this.get('model').save(); }
}
});
SpecialFormController = FormController.extend({
actions: {
submit: function() {
this.set('special', true);
this._super(); // doesn't work
}
}
});
Run Code Online (Sandbox Code Playgroud)