Skip to navigation
Jquery-ui autocomplete example of getting source data from the local pouchdb
26.05.16
jQuery(document).ready(function() { jQuery.global.cache = {}; jQuery(function() { jQuery( "#topsearch" ).autocomplete({ minLength: 0, source: function(request, response) { var term = request.term.toUpperCase(); if(term in jQuery.global.cache) { response(jQuery.global.cache[term]); return; } var db = new PouchDB('code'); db.allDocs({ include_docs: true, attachments: true, limit:8, startkey: term }).then(function (result) { var codes = []; for(i in result['rows']) { if(result['rows'][i]['id'] && result['rows'][i]['doc']['av21_PicturePath']) { var pic = result['rows'][i]['doc']['av21_PicturePath']; pic = 'http://www.imageserver.com/img/sal-60c_' + pic.replace('/','_'); codes.push( { value: result['rows'][i]['id'], label: result['rows'][i]['id'], desc: result['rows'][i]['doc']['av21_Description'], wholesale: result['rows'][i]['doc']['wholesale'], img: pic, } ) } } jQuery.global.cache[term] = codes; response(codes); }).catch(function (err) { }); }, focus: function( event, ui ) { jQuery( "#topsearch" ).val( ui.item.label ); return false; }, select: function( event, ui ) { jQuery( "#topsearch" ).val( ui.item.label ); jQuery( "#topsearch-id" ).val( ui.item.value ); return false; } }) .autocomplete( "instance" )._renderItem = function( ul, item ) { var html = ''; html += '
'; html += '
' + item.label + '
' + item.desc + '
'+ item.wholesale+ '
'; html += '
' return jQuery( "
" ) .append(html) .appendTo( ul ); }; }); });
https://jqueryui.com/autocomplete/#remote
Reply
Anonymous
Information Epoch 1732610631
Make every program a filter.
Home
Notebook
Contact us