- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用tag-it jQuery 插件。现在我需要自定义每个找到的项目结果:只需在找到的项目标签的左侧添加一个图像(用户头像)即可。
我已经包含了 tag-it.js 文件,除了我上面提到的问题之外,它工作得很好。
这是我的代码片段:
$("#searchForUsersAutocomplete").tagit({
tagSource: function(search, showChoices) {
findUsers(search.term, function(jsonFoundUsers, status)//externall API-call which returns list of users as Objects (jsonFoundUsers)
{
var users = new Array();
for (var i = 0; i < jsonFoundUsers.users.length; i++)
{
//users.push(jsonFoundUsers.users[i].userAvatar);//contain an image (user avatar). Where can I place it in order to render in autocomplete search result?
users.push(jsonFoundUsers.users[i].username);//populating users array which consists of "username" of each users
}
showChoices(users);
});
},
removeConfirmation: true,
});
我不明白我可以调整 tag-it.js 文件以便为每个项目添加图像(用户头像),但我找不到可以做到这一点的地方。 (我已经看过 the same question )
最终结果应该像 this
有人可以帮助我吗?任何努力都将受到高度赞赏。谢谢。
最佳答案
我已经找到解决办法了。也许这个答案对某人有帮助。
主要思想是申请monkeyPatchAutocomplete patch :
monkeyPatchAutocomplete();
function monkeyPatchAutocomplete()
{
$.ui.autocomplete.prototype._renderItem = function(ul, item) {
var regexp = new RegExp(this.term);
var highlightedVal = item.label.replace(regexp, "<span style='font-weight:bold;color:Blue;'>" + this.term + "</span>");
return $("<li'></li>")
.data("item.autocomplete", item)
.append("<a><img class='autocompleteUserAvatar' src='" + item.icon + "' />" + highlightedVal + "</a>")
.appendTo(ul);
};
}
var users;
$("#searchForUsersAutocomplete").tagit({
allowDuplicates: false,
removeConfirmation: true,
tagSource: function(search, showChoices) {
findUsers(search.term, function(jsonFoundUsers, status)//ajax-call to an externall server API
{
users = new Array();
for (var i = 0; i < jsonFoundUsers.users.length; i++)
{
var user =
{
value: jsonFoundUsers.users[i].username,
label: jsonFoundUsers.users[i].username,
icon: jsonFoundUsers.users[i].avatarUrl
};
users.push(user);
}
showChoices(users);
});
}
});
关于jquery - 如何自定义tag-it jQuery插件: needs to add image for each found item,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18624403/
我想知道,如果我的函数没有相似的名称,我是否需要使用命名空间? 另外我无法掌握从特定文件夹导入所有命名空间的方法... 最佳答案 I'm wondering, that if my functions
我运行 2to3 -f all -f idioms -f buffer -f set_literal -f ws_comma foo.py 输出: RefactoringTool: No change
我对 RoR 还是很陌生,我正在尝试使用 button_to delete 按钮删除一个对象。但是,使用我编写的代码,当我尝试将它获取到 destroy 方法的/needs/:id 时,它会将我带到/
当我运行代码时,我在 DEBUG Console 中发现了这个错误如下图所示错误: Restarted application in 2,804ms. [38;5;248m════════ Excep
我有一个实现 __dir__ 方法的类。但是,我并不完全确定 dir API 的一些细节。 A:__dir__ 是否真的需要返回一个列表?我的实现是使用 set 来避免两次列出属性,我需要在返回之前将
我正在尝试执行对非官方 Instagram API python 库的调用,在我修复了几个需要依赖项的错误之后,我被困在了这个错误上。 File "C:\Users\Pablo\Desktop\tx
我正在使用 SingleChildScrollView 和 Column 来显示滑动条和 gridview。 如果我在我的专栏中使用一些其他小部件,如文本、图像,应用程序显示正常。但是我的swiper
我正在尝试卸载 zsh 插件 (macos),我修改了 .zshrc 文件并从 中删除了 macos >plugin 列表,并删除路径 ~/.oh-my-zsh/plugins 中的 macos 文件
我正在尝试卸载 zsh 插件 (macos),我修改了 .zshrc 文件并从 中删除了 macos >plugin 列表,并删除路径 ~/.oh-my-zsh/plugins 中的 macos 文件
Exception caught by rendering library ═════════════════════════════════ RenderBox was not laid out:
我对 Python 很陌生。我正在试用 threading模块。我遇到了 Event对象。 事件对象有wait set clear职能。我了解等待、设置和清除正在做什么。但是我不太明白为什么会有一个单
我需要在 SQL Server 的 sql 查询中转义 [ select * from sometable where name like '[something]'; 我实际上正在寻找某个东西之前的
我的要求是这样的: 我在数据库和时区中保存以毫秒为单位的时间。例如,以毫秒为单位的时间是 1223123123232长时区是 Asia/Calcutta 。我必须将其转换为 Africa/Asmara
我的表中有两个整数列,其中第一列填充了一些随机数,第二列为空。现在是否可以将第一列按升序排序,同时按降序排序并显示为第二列?我有下表的示例。 初始表: col1 col2 5 7 3 9
我正在使用 Instruments 检查我的应用程序的内存泄漏并向我展示: NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ChangeAcc
我有课 class Person { // some other fields for this object std::vector relatives; } 然后是一个返回 Person
在下面的代码中,为什么需要 .page-wrap:after? 理论上,如果没有这个,粘性页脚不应该工作吗?为什么不呢? * { margin: 0; } html, body { heigh
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 8 年前。 Improve th
我看过维基百科的图数据库,还是不明白。 什么是“无索引邻接”? 可不可以理解为“不是把主键存到其他表的行,而是直接存这些行的物理位置” 最佳答案 当您的数据可以表示为图形( map 上的路线、一些树等
我是 AngularJS 的新手,但我真的很喜欢 AngularJS 的工作方式,所以我想将它部署为我的 Google 云端点后端的客户端。然后我立即遇到两个问题: 1、放在哪里myCallback
我是一名优秀的程序员,十分优秀!