【发布时间】:2015-05-08 20:10:17
【问题描述】:
免责声明:我对 Ember 很陌生。非常愿意接受任何人的任何建议。
我在 ArrayController 中有一个动作,应该设置一个 ObjectController 属性。创建新对象时如何访问正确的上下文来设置该属性?
这是我最近尝试的缩写应用代码:
ChatApp.ConversationsController = Ember.ArrayController.extend({
itemController: 'conversation',
actions: {
openChat: function(user_id, profile_id){
if(this.existingChat(profile_id)){
new_chat = this.findBy('profile_id', profile_id).get('firstObject');
}else{
new_chat = this.store.createRecord('conversation', {
profile_id: profile_id,
});
new_chat.save();
}
var flashTargets = this.filterBy('profile_id', profile_id);
flashTargets.setEach('isFlashed', true);
}
},
existingChat: function(profile_id){
return this.filterBy('profile_id', profile_id).get('length') > 0;
}
});
ChatApp.ConversationController = Ember.ObjectController.extend({
isFlashed: false
});
相关模板代码:
{{#each conversation in controller itemController="conversation"}}
<li {{bind-attr class="conversation.isFlashed:flashed "}}>
<h3>Profile: {{conversation.profile}} Conversation: {{conversation.id}}</h3>
other stuff
</li>
{{/each}}
【问题讨论】:
-
哦,抱歉,这是一个不必要且含糊的参考。我的意思是应该在调用的操作中设置该属性。我刚刚删除了引用。
标签: ember.js