在我的index.html,我有以下模板为什么这个Ember.TextArea没有绑定到控制器内容?
<script type="text/x-handlebars">
{{#with ChatApp.messagesController}}
{{view Ember.TextArea valueBinding="content.message" rows="12" cols="70"}}
{{/with}}
</script>
我的邮件模型看起来像这样
ChatApp.Message = Ember.Object.extend({
message: null
});
我的邮件视图和控制器看起来像这样
ChatApp.messagesView = Ember.View.extend({});
ChatApp.messagesController = Ember.ArrayController.create({
content: [],
text: '',
sendMessage: function() {
var newChatText = this.get('text');
socket.emit('sendchat', newChatText);
},
updateChat: function(username, text) {
var controller = this;
var content = this.get('content');
var newMessage = ChatApp.Message.create({ message: text });
content.push(newMessage);
console.log("update " + controller.get('content'));
controller.set('content', content);
}
});
我可以看到在console.log中,每次更新时都会将另一个模型对象添加到内容中,但文本区域未更新
这里是的jsfiddle网址http://jsfiddle.net/eDfKJ/
预先感谢您
我认为这个属性应该在'content。@ each'上计算,所以当插入一条新消息时它会被重新评估。 – 2012-08-02 15:57:01
不会在这种情况下valueBinding =“消息”?因为内容是数组和消息是我们的自定义监听器 – 2012-08-02 17:27:38
@ sly7_7感谢您的更正!确实更有意义 – 2012-08-03 21:52:33