显示一个div内用户名列表 [英] show the list of usernames inside a div
问题描述
我是新来的jQuery。在我的项目,我创建了一个类用户
在如下图所示的code:
静态ConcurrentDictionary<字符串,使用者名称> _users =新ConcurrentDictionary<字符串,使用者>();
//
//一些功能将值添加到列表_users
//
公开名单<使用者> GetConnectedUsers()
{
返回_users.Values.ToList();
}
我要显示在 DIV
#showUsernames值列表。如何通过使用jQuery做呢?
我试过低于未显示任何
/ *显示通讯录* /
$('#showUsernames')。追加(函数(){
chat.server.getConnectedUsers();
});
其中, chat.server
(signalr)调用服务器端code(聊天类)..
结果我认为解决方案有无关signalr。
如果上面的描述还不够,那么你可以通过我的code 的这里
编辑: User.cs
公共类用户
{
公共用户(字符串CONNID,字符串用户名)
{
名称=用户名;
的ConnectionId = CONNID;
}
公共字符串名称{;组; }
公共字符串的ConnectionId {搞定;组; }
}
服务器调用是异步(就像所有的JavaScript Ajax调用)。附加.done处理得到的结果(这是所有在文档 HTTPS ://github.com/SignalR/SignalR/wiki/SignalR-JS-Client-Hubs )。
更改code是这样的:
chat.server.getConnectedUsers()。完成(功能(用户){
对于(VAR I = 0; I< users.length ++我){
//在这里写下javascript来追加用户列表
}
});
I am new to jQuery. In my project, I created one Class User
in which the code is as shown below:
static ConcurrentDictionary<string, User> _users = new ConcurrentDictionary<string, User>();
//
// some function to add values to _users list
//
public List<User> GetConnectedUsers()
{
return _users.Values.ToList();
}
I want to show this list of values in div
#showUsernames. How to do this by using jQuery?
I tried the below which is not showing anything
/*display your contacts*/
$('#showUsernames').append(function(){
chat.server.getConnectedUsers();
});
where chat.server
(signalr) calls the server-side code(Chat class)..
I think the solution has nothing to do with signalr.
If the above description is not enough then you can go through my code here
EDIT: User.cs
public class User
{
public User(string ConnID, string Username)
{
Name = Username;
ConnectionID = ConnID;
}
public string Name { get; set; }
public string ConnectionID { get; set; }
}
Calls to the server are async (like all javascript ajax calls). Attach a .done handler to get the results (this is all in the documentation https://github.com/SignalR/SignalR/wiki/SignalR-JS-Client-Hubs).
Change your code to be like this:
chat.server.getConnectedUsers().done(function(users) {
for(var i = 0; i < users.length; ++i) {
// Write javascript here to append users to the list
}
});
这篇关于显示一个div内用户名列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!