jQuery UI autocomplete filter data

限于喜欢 提交于 2019-12-13 04:47:15

问题


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

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.

Any help is appreciated.

Thanks! Zel


回答1:


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
                    }
                })
            }
        });

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);
}



回答2:


On each textbox changed event, you will have to remove that item from the list and recall the function (from the plugin). You must have been calling all of the three functions at once.



来源:https://stackoverflow.com/questions/11929092/jquery-ui-autocomplete-filter-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!