マウスが出入りするときにブール値を切り替えることで、classNameBindingsを使用できます...
App.AnimalsListView = Ember.CollectionView.extend({
tagName: 'ul',
contentBinding: 'parentView.controller.content',
classNames: ['animals'],
elementId: 'animalsList',
itemViewClass: Ember.View.extend({
isHighlighted: false,
//highlight-name is the CSS Class to be applied when isHighlighted = true
classNameBindings: ['animal', 'isHighlighted:highlight-name'],
template: Ember.Handlebars.compile(
'{{view.content.title}}'
),
mouseEnter: function() {
//due to the following line, class will be applied when mouse enters
this.set('isHighlighted', true);
//this.toggleProperty('isHighlighted'); if using the latest ember
},
mouseLeave: function() {
//remove the class by making the value false when mouse leaves
this.set('isHighlighted', false);
//this.toggleProperty('isHighlighted'); if using the latest ember
}
})
});
お役に立てれば...
クリック時にアイテムを強調表示するための更新
この方法は、リスト内のアイテムをクリックしてルーティングすることを計画していて、繰り返してブールフラグをクリアする必要がない場合に特に便利です...
//define a reusable component this way
App.ListView = Ember.CollectionView.extend({
itemViewClass: Ember.View.extend({
tagName: 'li',
classNameBindings: ["isSelected:highlight-item"],
isSelected: (->
return this.get('content.id') === this.get('parentView.selected');
).property('parentView.selected')
})
})
App.PostsController = Ember.ArrayController.extend({
content: [{
name: "name1",
id: 1,
property1: "etc"
},
{
name: "name2",
id: 2,
property1: "etc"
}
]
})
//App.PostsView Handlebars
{{#collection App.ListView contentBinding="content" selectedBinding="controllers.postController.content.id"}}
Name: {{view.content.name}}<br>
Comments: {{view.content.property1}}
{{/collection}}
{{outlet}} //to connect App.PostView
//Now when an item is clicked you could send the context object or just the context id
ルーティングを使用していない場合は、Arasが言ったことを使用できます