2012-05-14 03:41
浏览 46

bootstrap typeahead获取结果数据源结果出现?

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


if i type in the data source using this format i do get results.


图片转代码服务由CSDN问答提供 功能建议


   &lt; input type =“text”class =“span1”id =“tag_field”data-items ='4'ata-provide =“typeahead”data-source ='[&lt;?php echo json_encode($ groups);  ?&gt;]'&gt; 
&lt;?php echo json_encode($ groups);  ?&gt; 

当我回显出json_encond($ groups)时,它会以这种格式显示

  {“  35“:”biology“,”37“:”经济学家“,”33“:”程序员“} 

如果我使用这种格式输入数据源 我确实得到了结果。

  data-source ='[“Alabama”,“Alaska”,“Arizona”]'&gt; 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dpli36193 2012-05-14 03:48

    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:

    $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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题