ユーザーがオンラインかどうかを確認するSignalR messagingHubがあります。データ属性IDを持つDOM要素があるかどうかを確認し、それらの要素を更新するデータ属性
接続したユーザーのIDとステータスを確認したら、データ属性を含むDOM要素をユーザーIDで更新し、ステータスを更新する必要があります。
基本的には、どのユーザーがオンラインになっているのか、どのユーザーがいないのかを示すために、各DOM要素に異なるクラスをWebサイトに表示する必要があります。あなたが変更イベントを使用して再なぜ私はとにかく場合は、最初に削除して、例のように、セレクタを使用し、把握カント
chatMessagingHub.on('updateUserOnlineStatus', function (userId, isOnline) {
var status = (isOnline) ? 'online' : 'offline';
console.log('userid: ' + userId + ' status: ' + status);
// Check the user id matches any dom elements with a data-attr userid
if($('[data-userId]') == userId) {
// Update the selected dom elements data-status attributes
$(this).attr('[data-status]', isOnline);
// Detect the change and update the class of the dom element
$(this).on('change', function() {
// Check the value of the data-status parameter to add class
if($(this).attr('data-status') == 'offline') {
$(this).removeClass('online');
} else {
$(this).addClass('online');
}
});
}
});
として
$(this)
を使用傾けるようちょうど$(この).trigger(「変更」)を追加する機能のような孤立スコープを作成してはいけません。 – Thorinは$です(これはchatMessagingHubに参照されていますか? – Vanojx1
私は、一致するattrのユーザーIDがあるdom要素として$(this)をターゲットにしたい –