0
我正嘗試使用Ember CLI與rails API後端構建一個使用simple-auth-devise的簡單聊天應用程序。我對Ember很新。我有以下設置:Ember識別當前用戶
- has_many消息的對話模型。每條消息都屬於用戶。
- 它加載的對話,並顯示該消息被寫入當前用戶的所有郵件
我的問題是找出一個對話/顯示路線。我可以識別路徑中的當前用戶並將其傳遞給控制器,但我不確定如何在模板中執行某些操作,而這是以此爲條件的。下面是代碼:在我想要做這樣的事情的模板
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
return this.store.find('conversation', params.conversation_id);
},
// Get the current user
setupController: function(controller, model){
this._super(controller, model);
var currentUser = this.get('session').get('currentUser');
controller.set("currentUser", currentUser);
}
});
然後:
{{#each message in messages}}
{{message.body}}
{{#if message.isByCurrentUser }}
Written by me!
{{/if}}
{{/each}}
我不知道如何或在哪裏
的對話/顯示路線定義該message.isByCurrentUser方法以使用路由中定義的currentUser變量。
非常感謝提前。
問題解決了,謝謝! – AdamP 2015-03-02 13:42:31