javascript - Jquery autocomplete - how modify returned data -


i have code this:

$(document).ready(function () {     if ($('#au').length <= 0) {         return;     }     var $project = $('#au');     $project.autocomplete({         minlength: 4,          source: function (request, response) {             $.ajax({                 datatype: "json",                 type: 'post',                 cache: false,                 data: {term: request.term},                 url: '/movies/ajax/',                  success: function (data) {                     if (isnan($('#au').val())) {                          response($.map(data, function (item) {                             return {                                  label: item.movies__name + " " + "(" + item.movies__id + ")",                                 value: item.movies__name                             }                         }));                     } else {                         response($.map(data, function (item) {                             return {                                 label: item.movies__id + " " + "(" + item.movies__name + ")",                                 value: item.movies__id                             }                         }));                     }                 }             });         },         select: function(event, ui) {             $("#au").val(ui.item.value);             $("#au").submit();         },           create: function (event, ui) {         },         open: function (event, ui) {          }     });  }); 

this code works fine. basicly when type in form "alie", get

alien(22) aliens2(32) aliens3(43)

or when type id istead of movie name, get:

(22)alien (22)other , on....

so code returns list of data - movie , id.

and want, have first result without id, when type movie name "alie" get:

alien alien(22) aliens(32)

first match without id.

thanks replies.

response($.map(data, function (item, i) {       return {          label: item.movies__name + (i != 0 ? " (" + item.movies__id + ")" : ""),          value: item.movies__name       } })); 

use index in map function. if 0, don't show id.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -