Javascript 单击用户';名单上的名字,韩元';t添加个人';她叫什么名字
我已经建立了一个基本的socket聊天程序。当人们登录时,他们的名字会被添加到在线用户列表中(在左边)。当用户单击其他联机用户之一时,名称应附加到顶部的div中。但正如您所看到的,它显示: div class=“well”>空(图中右上角区域) 服务器似乎没有捕捉到列表中的人的姓名。 我错过了什么 下面是聊天内容的图片 客户端:Javascript 单击用户';名单上的名字,韩元';t添加个人';她叫什么名字,javascript,jquery,node.js,sockets,Javascript,Jquery,Node.js,Sockets,我已经建立了一个基本的socket聊天程序。当人们登录时,他们的名字会被添加到在线用户列表中(在左边)。当用户单击其他联机用户之一时,名称应附加到顶部的div中。但正如您所看到的,它显示: div class=“well”>空(图中右上角区域) 服务器似乎没有捕捉到列表中的人的姓名。 我错过了什么 下面是聊天内容的图片 客户端: //Whispering $("#people").on('click', '.list-group-item', function(){ var
//Whispering
$("#people").on('click', '.list-group-item', function(){
var peopleName = $(this).siblings("span").text();
var peopleID = $(this).attr("id");
socket.emit("whispering", peopleID);
});
socket.on("addWhispering", function(id) {
$(".chatToInfo").empty();
$(".chatToInfo").append('div class="well">' + id + '</div>');
});
缺少
服务器是否接收到正确的id?服务器端的人员
-数组可能有问题吗?我添加了缺少的$(此).attr(“id”)
在客户端返回正确的id吗?它返回null。
var people = {};
socket.on("connection", function(client) {
client.on("join", function(name){
console.log("Someone joined the chat", name);
roomID = null;
people[client.id] = {"name" : name, "room" : roomID};
sizePeople = _.size(people);
sizeRooms = _.size(rooms);
socket.sockets.emit("update-peopleCount", {people: people, count: sizePeople});
socket.sockets.emit("update-people", {people: people});
socket.sockets.emit("roomList", {rooms: rooms, count: sizeRooms});
client.emit("updateToSelf", "You have connected to the server. Join or create room to chat");
client.broadcast.emit('updateToOthers', name + " is online.");
clients.push(client); //populate the clients array with the client object
});
client.on("whispering", function(id) {
var person = people[id];
client.emit("addWhispering", person);
console.log("Whisper caught");
});