以下似乎不起作用:
//Global variable needed for Websocket methods
var dispatcher = new WebSocketRails(document.location.host+'/websocket')
//dispatcher.state = 'connected' or 'disconnected'. This automatically updates
// its value if connected or not. I want to bind this value to a property below.
App.MessagesController = Ember.ArrayController.extend({
isConnectedBinding: 'dispatcher.state', //also tried dispatcher.state w/o quotes, didn't work
isConnected: (function() {
alert('!!!!'); //This alert never pops up
if (this.isConnectedBinding === 'connected') {
return true;
} else {
return false;
}
}).property('isConnectedBinding')
});
我在Ruby on Rails服务器上使用Websocket-rails gem,前端使用Emberjs 1.5.1。
我测试过dispatcher.state
确实改变了它的价值(假设我暂时关闭了我的本地服务器:'connected' - >'disconnected')。所以我猜它必须与Emberjs绑定。我还发现使用Chrome控制台时,App.__container__.lookup('controller:messages').isConnected
的值始终为undefined
,而且从未true
也不是false
非常感谢任何帮助。
答案 0 :(得分:0)
只需从isConnectedBinding: 'dispatcher.state'
中删除Binding和单引号,因为dispatcher是一个全局变量。请参阅此jsbin,您将会有所了解。