我在 UI 上有多个网格,并希望通过 signalR 进行更新。如果有一些变化,那么只更新相应的网格,其余的网格将保持原样。是否可以为不同的网格创建不同的连接并相应地为每个客户端更新。还必须维护不同客户端的连接 ID。那么,有没有可能找到这种情况的方法?寻找一些解决方案或建议。
服务器端
public class RealTimeEndPoint : PersistentConnection
{
//Create array to maiantain connections
static List<string> connectedUserId = new List<string>();
//Called when the first connection is made
protected override Task OnConnected(IRequest request, string connectionId)
{
return Connection.Broadcast("Connection " + connectionId + " connected");
}
//Called when connection is disconnected
protected override Task OnDisconnected(IRequest request, string connectionId)
{
connectedUserId.Remove(connectionId + ":" + request.User.Identity.Name);
return Connection.Broadcast("Connection " + connectionId + " disconncted");
}
//Sends a value to specified signal
protected override Task OnReceived(IRequest request, string connectionId, string data)
{
connectedUserId.Add(connectionId + ":" + request.User.Identity.Name);
return Connection.Send(connectionId, "Connection " + connectionId + " sent " + data);
}
}
客户端
myGrid1.on('rowcollapse', function (event) {
GridConnection.stop();
});
myGrid1.on('rowexpand', function (event) {
var row = event.args.rowindex;
var value = myGrid1.jqxGrid('getcellvalue', row, "Name");
GridConnection.start().done(function () {
GridConnection.send("P" + value);
});
我需要的是展开连接并通过 signalR 更新数据,而在折叠后它应该断开连接。网格的数量将不止一个。希望这有助于澄清我的观点。