我需要從不同的地方訂閱同一集線器幾次,例如:使用jQuery的回調,而不是RPC在SignalR樞紐
function firstPlace(targetHub){
targetHub.client.onSomeEvent = function(data){
alert('hello from first place');
};
}
function secondPlace(targetHub){
targetHub.client.onSomeEvent = function(data){
alert('hello from second place');
};
}
firstPlace($.connection.clientHub);
secondPlace($.connection.clientHub);
我想基於回調(如jquery callbacks)擁有的功能。
function firstPlace(targetHub){
targetHub.client.onSomeEvent.add(function(data){
alert('hello from first place');
});
}
function secondPlace(targetHub){
targetHub.client.onSomeEvent.add(function(data){
alert('hello from second place');
});
}
firstPlace($.connection.clientHub);
secondPlace($.connection.clientHub);
我知道它可以很容易地使用一些代理對象實現,但也許有一些JavaScript的魔術,我不知道?
我讀過你的wiki,有太多的功能,它的項目,我(我不想在服務器端對此功能進行任何配置更改)。是否有可能連接客戶端偵聽器只更改客戶端?我試圖自己初始化你的Event聚合器(var my aggregator = new signalR.EventAggregator();),但它會拋出多個錯誤(Uncaught TypeError:無法讀取未定義jquery.signalR.eventAggregator-1.3.110.0.min的屬性'client' .js:1 Uncaught TypeError:無法讀取屬性'genericConstructor'的未定義) – Ivan 2014-10-20 10:13:36