Ruby on rails 如何绑定到Emberjs中的全局变量

Ruby on rails 如何绑定到Emberjs中的全局变量,ruby-on-rails,ember.js,websocket,Ruby On Rails,Ember.js,Websocket,以下似乎不起作用: //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

以下似乎不起作用:

//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')
});
我正在RubyonRails服务器上使用Websocket rails gem,前端是Emberjs 1.5.1

我测试了
dispatcher.state
是否确实更改了它的值(比如我临时关闭本地服务器:'connected'->'disconnected')。所以我猜它一定是沿着Emberjs绑定的。我还使用Chrome控制台发现,
App.\uuuu容器\uuuuuu.lookup('controller:messages').isConnected
的值始终是
未定义的
,从来都不是
真的
假的


任何帮助都将不胜感激。

只需删除
isConnectedBinding:'dispatcher.state'
中的绑定和单引号,因为dispatcher是一个全局变量。参考这一点,你会有一些想法。

不起作用。在Chrome控制台上尝试了这一点:在我临时关闭服务器后,dispatcher.state从“connected”变为“disconnected”,在“connected”中,我希望
App.\uuu container\uuuu.lookup('controller:messages')。isConnected
也变为“disconnected”,但它没有。它仍然“连接”。如果我没有弄错的话,这是因为isConnectedBinding是一个绑定,而isConnected:dispatcher.state将被视为一个普通属性,其值=
dispatcher.state
因此将始终是“connected”值。请参阅(我编辑了您的链接),您是否找到了此问题的解决方案