Jquery Autocomplete from json list all elements -
in script autocomplete set json file:
script
<script type="text/javascript"> $("#tags").autocomplete({ source: function(request, response) { $.ajax({ url: "test.json", datatype: "json", data: { term: request.term }, success: function(data) { response($.map(data, function(item) { homecoming { label: item.name_test }; })); } }); } }); </script>
html
<div class="ui-widget"> <label for="tags">tags: </label> <input id="tags"> </div>
the json file
[{ "id_test": "7", "name_test": "tejido", "price": "65" }, { "id_test": "8", "name_test": "semen", "price": "120" }, { "id_test": "6", "name_test": "saliva", "price": "20" }, { "id_test": "2", "name_test": "analisis urinario", "price": "150" }, { "id_test": "3", "name_test": "analisis sanguineo", "price": "1502" }, { "id_test": "4", "name_test": "analisis fecal", "price": "20" }]
but when type name input, elements listed.
what error?
when utilize remote source, code using, must need filter results in server side or in success
callback ajax call. in case can utilize like:
... success: function (data) { var tag_val = $("#tags").val(); response($.map(data, function (item) { //filtering results.... if (item.name_test.indexof(tag_val) != -1) { homecoming { label: item.name_test }; } })); }
jquery json jquery-ui jquery-ui-autocomplete
No comments:
Post a Comment