jQuery UI自动完成过滤器数据 [英] jQuery UI autocomplete filter data
问题描述
我是jquery的新手,一旦选择了项目,我就会被分配过滤出该列表.有3个使用自动完成功能的文本框.
I am new to jquery and I was assigned to filter out the list once the item is already selected. There are 3 textboxes that uses the autocomplete.
来源:苹果,橙子,芒果
source: apple, orange, mango
文本框1 =苹果 文本框2 =应该在列表中过滤掉苹果.它应该只显示橙色和芒果.
textbox 1 = apple textbox 2 = apple should be filtered out in the list. it should only display orange and mango.
我能够过滤源,但是列表仍然显示该项目.但是,一旦刷新页面,源就会更新.我已经找到了这个问题,这是链接,但在我的情况下,我没有添加想将其过滤掉.
I was able to filter the source but the list still display the item. But the source gets updated once I refresh the page. I have found this question, here's a link but in my case instead of adding, i wanted to filter it out.
感谢您的帮助.
谢谢! 泽尔
推荐答案
我该怎么做...将第一个文本框的值传递回服务器(每次自动完成,反之亦然)
What i would do... Pass the value of the first textbox back to the server (& vice versa for each auto complete)
您可以尝试这样的事情.
You could try something like this.
JQuery
$('#auto2_id').autocomplete({
source: function (request, response) {
$.ajax({
url: 'some_url/SomeAction',
dataType: "json",
data: {
term: request.term,
filter: $('#auto1_id').val()
},
success: function (data) {
//do something
}
})
}
});
服务器端 (不确定您使用的是哪种语言. 但在c#中(粗略的代码示例))
server side (not sure what language you're using. but in c# (rough code sample))
public ActionResult SomeAction(string term, string filter)
{
var data = _repo.GetAllCached().Where(o => o.Text != filter && o.Text.Contains(term));
return Json(data , JsonRequestBehavior.AllowGet);
}
这篇关于jQuery UI自动完成过滤器数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!