[英]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
$driver
using following code $driver
的所有电子邮件列表 $emails = array_column($driver, 'email');
"
) and seperated by comma ( ,
) "
)并用逗号分隔( ,
) $csv = "\\"" . implode("\\",\\"", $emails) . "\\"";
<input type="text" class="form-control input-lg typeahead" autocomplete="off" data-provide="typeahead" data-source='[<?php echo $csv; ?>]' id="email" name="email">
data-source
attribute has single quote as start and end. data-source
属性的单引号为start和end。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.