【发布时间】:2016-04-17 14:42:29
【问题描述】:
我正在开发聊天应用程序。我有组件模板 - 房间
<div class='border rooms'>
<button class="add-room-container">
<div >Add room</div>
</button>
{{#each model as |room|}}
<button class="room-container"
{{action "onRoomClicked" room.id}}
{{bind-attr class="currentRoomId===room.id:currentRoom"}}>
<div class="deleteRoom" {{action "deleteRoom" room.id bubbles=false}}>
X
</div>
<div>{{room.name}}</div>
<div>{{room.createdAt}}</div>
</button>
{{/each}}
</div>
和组件js文件 从“ember”导入 Ember;
export default Ember.Component.extend({
actions: {
onRoomClicked(roomId) {
this.set('currentRoomId', roomId);
},
deleteRoom(room) {
console.log('room removed');
}
} });
我的线路有问题
{{bind-attr class="currentRoomId===room.id:currentRoom"}}
我想检查当前按钮是否是最后一个被点击的按钮(它在 onRoomClicked 中设置),如果是,则将 currentRoom 类添加到按钮
我试图设置动态属性,但我不知道如何从组件中访问当前模型(房间)ID,然后像在模板中一样进行比较
【问题讨论】:
标签: javascript html css ember.js