Reputation: 1331
i am not getting any results when i search.
<input type="text" class="span1" id="tag_field" data-items='4' data-provide="typeahead" data-source='[<?php echo json_encode($groups); ?>]' >
<?php echo json_encode($groups); ?>
when i echo out json_encond($groups) it appears in this format
{"35":"biology","37":"economist","33":"programmers"}
if i type in the data source using this format i do get results.
data-source='["Alabama","Alaska","Arizona"]'>
Upvotes: 0
Views: 2664
Reputation: 5454
I think the Typeahead plugin is expecting an Array of Strings as the data-source
. Your json_encode
is creating an Object and you're just wrapping it in an array when you echo it.
You want something like this:
<?php
$groups = array("biology", "economist", "programmers");
?>
<input type="text" class="span1" id="tag_field" data-items='4' data-provide="typeahead" data-source='<?php echo json_encode($groups); ?>'>
You can use the array_values() function in PHP to ensure your $groups
is a basic numerically indexed array.
Upvotes: 2