views:

30

answers:

1

Hi, I've a problem with jqueryui's autocomplete.When i filter results.it's filtering word like it contains,but i want like startswith.How can i do that?(Words are coming from a xml file)

Thanks.

Edit:Here is my complete jq code:

$(function () {


         function log(message) {
             if ($("#<%=From1.ClientID %>").val() == "") {
                 $("#<%=From1.ClientID %>").val(message);
             }
             else if ($("#<%=From2.ClientID %>").val() == "")
             { $("#<%=From2.ClientID %>").val(message); }
             else { $("#<%=From3.ClientID %>").val(message); }

         }

         function log2(message) {
             if ($("#<%=To1.ClientID %>").val() == "") {
                 $("#<%=To1.ClientID %>").val(message);
             }
             else if ($("#<%=To2.ClientID %>").val() == "")
             { $("#<%=To2.ClientID %>").val(message); }
             else { $("#<%=To3.ClientID %>").val(message); }

         }

         $.ajax({
             url: "airports.xml",
             dataType: "xml",
             success: function (xmlResponse) {
                 var data = $("airport", xmlResponse).map(function () {
                     return {
                         label: $("code", this).text() + ", " + $("name", this).text() + ", " + $("city", this).text() + " / " + $("country", this).text(),
                         value: $("code", this).text(),
                     };
                 }).get();
                 var data2 = $("airport", xmlResponse).map(function () {
                     return {
                         label: $("code", this).text() + ", " + $("name", this).text() + ", " + $("city", this).text() + " / " + $("country", this).text(),
                         value: $("code", this).text() ,
                     };
                 }).get();

                 $("#<%=ToL.ClientID %>").autocomplete({
                     source: data2,
                     minLength: 2,
                     select: function (event, ui) {
                         log2(ui.item ? (ui.item.value) : "Nothing selected, input was " + this.value);
                     }
                 });
                 $("#<%=FromL.ClientID %>").autocomplete({
                     source:data,
                     minLength: 2,
                     select: function (event, ui) {
                         log(ui.item ? (ui.item.value) : "Nothing selected, input was " + this.value);
                     }
                 });
             }
         })
     });
+1  A: 

If you're treating it as a remote data source it will fire an AJAX request and you can then query your data however you like, so whether the value is at the start of the string, or any part of a string.

ILMV