jQuery Mobile: Listview Filter Search Callback Function

我的未来我决定 提交于 2019-12-06 02:41:39

问题


Hey so I want to have a filter search such that you enter two letters of a search and the corresponding results appear in a list view. I can't load the entire list as is typical with the jqm listview because its way too big. Can someone please show me how to do this...its a bit beyond my scope of understanding the API.

I know how to use the autocomplete widget for jquery, but I want the results formatted as a listview. So a textbox, and then under it the listview formatted results, but only after two letters have been entered would I like it to display results, that way it doesn't show a giant list which would take too long to load.


回答1:


Check out this here: https://github.com/commadelimited/autoComplete.js
Seems like what you are looking for.
Alex




回答2:


I will assume your call is returning JSON:

$("#txtInput").change(function() {
   var val = $(this).val();
   if (val.length >= 2)
   {
       // Do Ajax call
        $.ajax({
        type: "POST",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        url: '/SomeURL/',
        data: "{'searchText': '" + val + '}',
        success: function (data) {
           $("#divListArea").empty();
           var i;
           for (i = 0; i < data.length; i++)
           {
              $("#divListArea").append("<div key=" + data[i].Id + ">" + data[i].SomeProperty + "</div>");
           }
           $("#divListArea div").each(function() {
              $(this).click(function() [
                 // Do something
                 var id = $(this).attr('key');
              });
           });
         },
         complete: function () {

         }
    });
   }
});


来源:https://stackoverflow.com/questions/9720816/jquery-mobile-listview-filter-search-callback-function

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