- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 Jquery UI 自动完成代码,可以从 ajax 请求中获取数据,当我获取数据时,结果已经放入附加了自动完成功能的输入框中。我的问题是我还有其他数据以及将与自动完成结果一起发布的数据。
我试图获取我需要的所有内容,并将其放入带有分隔符的单个字符串中,以便我可以在客户端对其进行 split() 。我想将其他数据保存在隐藏文本字段中
这是我的代码
<div id="01ac091c834d81b41f0ef4b6eb09cde90bb9aa1a" style="display:none" title="Add Member">
Type the name of the member
<br>
<br>
<div style="text-align:center">
<input type="text" id="txtUserFind" size="35">
</div>
<input type="hidden" id="hidtxtUserFind-nickname">
<input type="hidden" id="hidtxtUserFind-userhash">
<input type="hidden" id="hidtxtUserFind-picture">
<input type="hidden" id="hidtxtUserFind-sex">
</div>
<script type="text/javascript">
head(function() {
$(":button:contains('Select User')").attr("disabled","disabled").addClass("ui-state-disabled");
$("#txtUserFind").keydown(function(){
$(":button:contains('Select User')").attr("disabled","disabled").addClass("ui-state-disabled");
});
$("#txtUserFind").change(function(){
var userdetails = $("#txtUserFind").val().split(";");
alert($("#txtUserFind").val());
/*
0 profiles.nickname,
1 profiles.firstname,
2 profiles.surname,
3 users.user_hash,
4 profiles.sex,
5 profiles.picture
*/
$("input#hidtxtUserFind-nickname").val(userdetails[0]);
$("input#txtUserFind").val(userdetails[1] + " " + userdetails[2]);
$("input#hidtxtUserFind-userhash").val(userdetails[3].replace("u-",""));
$("input#hidtxtUserFind-sex").val(userdetails[4]);
if(userdetails.length > 5){
$("input#hidtxtUserFind-picture").val(userdetails[5]);
}
});
$("<?php echo $tagmemberbtn; ?>").click(function(){
$("#01ac091c834d81b41f0ef4b6eb09cde90bb9aa1a").dialog({
modal:true,
resizable: false,
height:250,
width:400,
hide:"fade",
open: function(event, ui){
searchdone = false;
$(":button:contains('Select User')").attr("disabled","disabled").addClass("ui-state-disabled");
},
beforeClose: function(event, ui){
$("#txtUserFind").val("");
},
buttons:{
"Select User":function(){
$(this).dialog("close");
},
"Close":function(){
searchdone = false;
$("#txtUserFind").val("");
$(this).dialog("close");
}
}
});
});
$(function() {
var cache = {},
lastXhr;
$("#txtUserFind").autocomplete({
source:function(request,response) {
var term = request.term;
if ( term in cache ) {
response(cache[term]);
return;
}
lastXhr = $.getJSON(cvars.userburl+"getusers", request, function(data,status,xhr) {
stopAllAjaxRequest();
cache[ term ] = data;
if ( xhr === lastXhr ) {
response( data );
}
});
},
minLength: 1,
select: function(event, ui) {
$(":button:contains('Select User')").removeAttr("disabled").removeClass("ui-state-disabled");
}
}).data("autocomplete")._renderItem = function(ul,item){
if(item.picture==null){
//know if girl or boy
if(item.sex<=0){
item.picture = cvars.cthemeimg + "noimagemale.jpg";
}
else{
item.picture = cvars.cthemeimg + "noimagefemale.jpg";
}
}
else{
item.picture = cvars.gresuser + "hash=" + item.user_hash.replace("u-","") +"&file="+item.picture.replace("f-","");
}
var inner_html = '<a><div class="autocomplete-users-list_item_container"><div class="autocomplete-users-image"><img src="' + item.picture + '" height="35" width="35"></div><div class="label">' + item.nickname + '</div><div class="autocomplete-users-description">' + item.firstname + " " + item.surname + '</div></div></a>';
return $("<li></li>")
.data("item.autocomplete",item)
.append(inner_html)
.appendTo(ul);
};
});
});
最佳答案
你的想法是对的,你必须使用回调作为source
参数。我在这里整理了一个例子:
如果您阅读 documentation仔细地写着:
The third variation, the callback, provides the most flexibility, and can be used to connect any data source to Autocomplete. The callback gets two arguments:
A request object, with a single property called "term", which refers to the value currently in the text input. For example, when the user entered "new yo" in a city field, the Autocomplete term will equal "new yo".
A response callback, which expects a single argument to contain the data to suggest to the user. This data should be filtered based on the provided term, and can be in any of the formats described above for simple local data (String-Array or Object-Array with label/value/both properties). It's important when providing a custom source callback to handle errors during the request. You must always call the response callback even if you encounter an error. This ensures that the widget always has the correct state.
这是我在演示中使用的示例实现:
$("#autocomplete").autocomplete({
source: function(request, response) {
$.ajax({
url: "/echo/html/", // path to your script
type: "POST", // change if your script looks at query string
data: { // change variables that your script expects
q: request.term
},
success: function(data) {
// this is where the "data" is processed
// for simplicity lets assume that data is a
// comma separated string where first value is
// the other value, rest is autocomplete data
// the data could also be JSON, XML, etc
var values = data.split(",");
$("<div/>").text("Other value: " + values.shift()).appendTo("body");
response(values);
},
error: function() {
response([]); // remember to call response() even if ajax failed
}
});
}
});
关于javascript - 拦截并预处理 jQuery-ui 自动完成数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10242165/
当我同时定义两条指令时,如何做到这一点,我会收到编译错误? 在这里我想要错误 #define ENG #define POL #if defined POL #if defined ENG 这里没有
我有actix-web,并且调试困难,因为记录器仅在最后写入,如果出现故障,则根本不会写入。RUST_LOG=actix_web=debug,actix_server=debug let server
对于以下有关数据预处理聚类的问题,我很困惑,在互联网上找不到令人信服的答案。 根据Python documentation ,当我们使用 sckit learn 库中的内置命令进行预处理时,假设数据被
我无法理解预处理器的工作原理以及 ## 在这个特定示例中代表什么 #include #define TEMP_KEY(type,Key) (TEMP_##type | Key) enum TEMPK
我一直在尝试对 Kaggle 上的 Sentiment140 数据库进行一些预处理:https://www.kaggle.com/kazanova/sentiment140 我使用的代码是这样的: i
例如,考虑在 Keras 中微调 Resnet50 模型。 For example here : from keras.applications.resnet50 import ResNet50 fr
我想预处理 JavaScript 属性名称以将其转换为 { 'extension': object, 'config': {id: 1} } 到 { extension: object,
我在编译 C 程序时在预处理步骤中遇到错误。 奇怪的是,我可以运行预处理而没有错误或警告: gcc -I/usr/local/libpng-1.6.24/include -Wall -std=c99
我很好奇 GCC 预处理步骤的输出。更准确地说,以下两行的目的是什么: # 1 "" # 1 "" 我知道格式是 但我不明白本节中可能会出现什么类型的数据。它的目的是什么? 谢谢! 最佳答案 目的是
我需要能够预处理多个 C# 文件作为项目的预构建步骤,检测方法的开始,并在方法开始处插入生成的代码,在任何现有代码之前。但是,我在检测方法的打开时遇到问题。我最初尝试了一个正则表达式来匹配,但最终出现
如何使用 C 预处理自动生成以下代码模式(访问器)? // Immutable accessor. const auto& member1 () const { return _member1;
我正在考虑分两个阶段实现 C 预处理器,其中第一阶段将源文件转换为预处理标记数组。这对于简单性和性能都有好处,因为当项目中的多个文件包含头文件时,不需要重做标记化工作。 障碍: #define f(x
有没有办法“预处理”C99 样式的二合字母以获得 C 文件(或 .i 预处理源),使得生成的文件不包含任何二合字母? 例如,给出以下源代码: %:define N 5 int main() = ;
如何使用 browserify 预处理函数调用? 在一个大的 js 文件中,有时我需要将一个 JSON 对象传递给一个变量,但这个 JSON 对象只能通过函数调用创建: var myvar = Rac
我正在对电视镜头中的字幕应用 OCR。 (我正在使用带 C++ 的 Tesseact 3.x)我正在尝试拆分文本和背景部分作为 OCR 的预处理。 这是原图: 然后,预处理图像: OCR结果为:Sic
我正在开发一个函数,该函数采用众所周知的参数范围,但我不想为每种情况编写许多不同的函数。有没有一种方法可以定义函数的“模式”并使预编译器根据这种模式生成函数? 例子。我有以下功能: int addit
我有一个包含多个脚本标签(接近 20 个)的 html 文件。我决定将所有 JS 文件连接成一个文件,然后缩小连接后的文件。我正在使用 ant 任务来连接并将这样做以进行缩小。我知道我需要提供非串联/
我想在 AngularJS 更新任何 HTML 之前添加一个预处理步骤。为了简单起见,让我们将 hello 的所有实例都加粗。 . 也就是说,如果我们让$scope.text = "hello wor
我正在使用 tess4j 作为来自 JAVA 的 tesseract 的包装器对图像运行一系列 OCR。 ocr 的过程仍然需要大量时间(有时甚至 5 秒),我正在努力加快它的速度。 我正在对图像进行
我一直在阅读有关 Phing 和 Ant 的文章,但我不确定这些工具中哪一个(如果有的话)对这种情况最有用。 它很容易是调试语句等,但我会给你我们的字面扫描。 我们有一个可下载的 PHP 应用程序的免
我是一名优秀的程序员,十分优秀!