简体   繁体   English

typeahead bootstrap不使用来自php页面的动态数据

[英]typeahead bootstrap not working with dynamic data from php page

I want to use typeahead on input text, but it's not working. 我想在输入文本上使用typeahead,但它不起作用。

my html : 我的HTML:

<link rel="stylesheet" type="text/css" href="<?php echo base_url('asset/css/typeahead.css')?>">

<?php foreach ($driver as $d) { ?>
    <input type="text" class="form-control input-lg typeahead" autocomplete="off" data-provide="typeahead" data-source="<?php echo $d['email']; }; ?>" id="email"  name="email">

<script src="<?php echo base_url('asset/js/typeahead.bundle.min.js') ?>"></script>

My controller : 我的控制器:

$this->db->select("*");
$this->db->from('user');
$query = $this->db->get();
$data['driver'] = $query->result_array();

When I start typing in input text, it shows nothing, it should be dropdown the email list provided from select query. 当我开始输入输入文本时,它什么也没有显示,它应该是下拉select查询提供的email列表。 No error return. 没有错误返回。

There is problem in your code. 您的代码中存在问题。 You are looping for each $driver and showing its email id in the data-source and the input tag is not closing. 您正在循环每个$driver并在数据源中显示其电子邮件ID,并且输入标记未关闭。

For using bootstrap typeaded 使用bootstrap typeaded

  1. Get list of all emails from $driver using following code 使用以下代码获取来自$driver的所有电子邮件列表
    $emails = array_column($driver, 'email');
  2. Create a string which will contain all the emails. 创建一个包含所有电子邮件的字符串。 All the emails should be wrapped in double quotes( " ) and seperated by comma ( , ) 所有电子邮件都应该用双引号括起来( " )并用逗号分隔( ,
    $csv = "\\"" . implode("\\",\\"", $emails) . "\\"";
  3. Now create the typeahed input tag 现在创建一个类型化的输入标记
    <input type="text" class="form-control input-lg typeahead" autocomplete="off" data-provide="typeahead" data-source='[<?php echo $csv; ?>]' id="email" name="email">
    Remember that the data-source attribute has single quote as start and end. 请记住, data-source属性的单引号为start和end。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM