0

I am trying to change source data of my autocomplete JQuery but i can't understand what kind of array i have to send in PHP at my JS function because i use this to change source data :

$( "#autocomplete" ).autocomplete('option', 'source', tab);

and i send this result to my JS function :

{"transport":{"voiture":"voiture","car":"car","avion":"avion"}}

my php for this result :

foreach ($result as $k => $v)  {        
    //Stockage des valeurs dans un tableau associatif 
        $listtransport[$v['transport']] = $v['transport'];
    }

Thanks in advance !

Salman A
  • 262,204
  • 82
  • 430
  • 521
VinceDMG
  • 111
  • 7

1 Answers1

0

This is the JSON accepted by the JqueryUI Autocomplete

[
    { 
      id:    elementId, 
      label: label,
      value: value to set when the element is selected
    },
    //Write other elements
]

You could build this array in the follow manner

$ayValues = array();

foreach ($result as $k => $v) {
    $ayValues[] = array(
        'id' => $v['transport']['id index'],         //This is the id of the value
        'label' => $v['transport']['label index'],   //This is the label show
        'value' => $v['transport']['value index']    //This is the value setted
    );
}

print json_encode($ayValues);

Without the content of $result it's impossible to write a clear response.

You could omit the id key

Ruben Giaquinto
  • 391
  • 1
  • 14