php - bootstrap typahead and mysql data retrieving -


i have followed tutorial http://blattchat.com/2013/06/04/twitter-bootstrap-typeahead-js-with-underscore-js-tutorial/ , working in own project. managed set hidden field id , submitting form page.

how can "local" array replaced array retrieved mysql database.

i tried http://www.codingforums.com/showthread.php?t=286412 did not work setting hidden field.

=====================================================================

after trying things following working.

<div class="content"> <form method="post" name="quicksearchform" id="quicksearchform" action=""> <fieldset> <input type="text" placeholder="quick search" id="quicksearch" class="quicksearch"> <input type="hidden" id="quicksearchid" name="quicksearchid"> <input type="hidden" id="quicksearchtype" name="quicksearchtype"> </fieldset> </form> </div>   <script> $(function($) {         $('.quicksearch').typeahead({       name: 'quicksearch',       valuekey: 'name',   local: [{"id":"1","name":"user1","type":"type1"},               {"id":"2","name":"user2","type":"type2"}              ]       }).on('typeahead:selected', function(event, datum) {      $('#quicksearchid').val(datum.id);      $('#quicksearchtype').val(datum.type);      $('#quicksearchform').submit();   }); }); </script> 

i have php file generates same output have put after local:. thing has done loading data php file (which json_encoded).

have tried defining information used local option outside function? start tackling way.

so... define stuff variable called data.

[         {            id: 0,            name: 'deluxe bicycle',             price: 499.98         },         {            id: 1,            name: 'super deluxe trampoline',            price: 134.99         },         {            id: 2,            name: 'super duper scooter',            price: 49.95         }      ] 

and in typeahead options...

$('input.product-typeahead').typeahead({      name: 'products',      header: '<h3>products</h3>',      local: data }); 

if can that, define data php variable instead, matching kind of structure in php portion of page. after retrieving info database, construct array of data need.

$data = array(structure of data need); 

then json_encode it's nice string javascript can interpret.

$data = json_encode($data); 

then in javascript use eval() or use jquery transform string javascript

var data = jquery.parsejson(<?php echo $data; ?>); 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -