【发布时间】:2014-04-11 10:59:14
【问题描述】:
以下似乎不起作用:
//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')
});
我在前端使用 Emberjs 1.5.1 的 Ruby on Rails 服务器上使用 Websocket-rails gem。
我测试了dispatcher.state 确实改变了它的值(比如我暂时关闭了我的本地服务器:'connected' -> 'disconnected')。所以我猜它必须沿着 Emberjs 绑定。我还发现使用 Chrome 控制台时,App.__container__.lookup('controller:messages').isConnected 的值始终是 undefined,而从来不是 true 也不是 false
任何帮助将不胜感激。
【问题讨论】:
-
你找到解决方案了吗
标签: ruby-on-rails ember.js websocket