bootstrap typeahead仅显示结果的第一个字符

时间:2012-10-07 22:36:47

标签: php javascript html twitter-bootstrap

目前,当我在php

中创建时,我的预先输出看起来像这样
    echo '<input type="text" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[,';
while ( $rowresult = mysql_fetch_assoc($titlequery) ) {
      echo '{value:&quot;'.htmlspecialchars($rowresult['title']).'&quot;'."},";
}
      echo ']">';

输出如下:

  <input type="text" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[,{value:&quot;2010-11 Graf Intern&quot;},{value:&quot;2nd Year Finance Explorer, Mizani &amp; L'Oreal Technique&quot;},{value:&quot;A&amp;R Intern&quot;},{value:&quot;Account Executive&quot;},{value:&quot;Account Manager&quot;},{value:&quot;Account Service Representative&quot;},{value:&quot;Account Strategist&quot;},{value:&quot;Accountant&quot;},{value:&quot;Accounting Intern&quot;},{value:&quot;Accounting Intern/Analyst&quot;},{value:&quot;Accounts payable&quot;},{value:&quot;Acquisition Marketing Intern&quot;},{value:&quot;Acquisitions Associate&quot;},{value:&quot;Acting Manager&quot;},{value:&quot;Acting Software Manager&quot;},{value:&quot;Administrator&quot;},{value:&quot;Admissions Ambassador&quot;},]">

不幸的是,它只显示了它能够找到的每个值的第一个字符(值是bootstrap的默认值。)

编辑:

问题围绕着格式化结果,实际上,正在发生的事情是Javascript试图引用一个不存在的数组,所以它采用了元素[0],它是第一个字符。

1 个答案:

答案 0 :(得分:1)

尝试使用此解决方案:

<?
$chars = array(":", "'", "?", '"', "/");
while ( $rowresult = mysql_fetch_assoc($titlequery) ) {
      $Str = $rowresult['title'];
      $Data[] = str_replace($vowels, "", $Str);
}
if(isset($Data)): ?>    
<input type="text" style="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="[<?= implode(',', $Data) ?>]">
<?php endif; ?>