- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Bootstrap-3-Typeahead here用于我的 mysql 自动完成功能。
我需要从选定的 item_name afterSelect 中获取 item_code,例如
$('#item_code').val(this.item_code);
$('input.item_name').typeahead({
minLength: 3,
source: function (query, process) {
$.ajax({
url: 'function/load-item.php',
type: 'POST',
dataType: 'JSON',
data: 'query=' + query,
success: function(data) {
var newData = [];
$.each(data, function(){
newData.push(this.item_name);
});
return process(newData);
}
});
},
afterSelect: function(){
$('#item_code').val( ... ... ... ... );
}
});
<?php
session_start();
include ('../include/connect.php');
$query = 'SELECT item_code,item_name FROM master_item';
if(isset($_POST['query'])){
$query .= ' WHERE item_name LIKE "%'.$_POST['query'].'%"';
}
$return = array();
if($result = $conn->query($query)){
// fetch array
while ($row=mysqli_fetch_assoc($result))
{
$return[] = $row;
}
// free result set
$result->close();
// close connection
$conn->close();
$json = json_encode($return);
print_r($json);
}
最佳答案
这是为了那些在不久的将来可能遇到同样问题的人的利益。
下面是获得相同功能的另一种简单方法 使用 JQuery 和 bootstrap-3-typeahead.js or bootstrap-3-typeahead.min.js :
例子
var url = "codePath/searchCode.php";
$('.typeahead').typeahead({
source: function (query, process) {
return $.get(url, { query: query }, function (data) {
console.log(data)
return process(data);
});
},
//this triggers after a value has been selected on the control
afterSelect: function (data) {
//print the id to developer tool's console
console.log(data.id);
}
});
关于twitter-bootstrap - Bootstrap-3-Typeahead afterSelect 获取 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35402487/
我有一个 TreeView 控件。假设我有 5 个节点。在选择一个节点时,我用该 SelectedNode 下的所有目录填充一个 ListView。然后,我单击一个按钮,它修改了 ListView 项
我尝试使用“window.location.hash = '#section3';”选择后跳转,但它不起作用。 $('#inputField').typeahead({ source:
我在 Winforms 应用程序中有一个 TreeView 控件,基本上目标是显示一个包含 TreeView 控件的表单,我想显示一个节点打开(简单 - EnsureVisible)并选中的表单。 我
我正在使用 Bootstrap-3-Typeahead here用于我的 mysql 自动完成功能。 我需要从选定的 item_name afterSelect 中获取 item_code,例如 $(
我的项目中有 MyForm.cs, MyForm.Designer.cs 文件,在 MyForm.Designer.cs 中我是这样做的: private System.Windows.Forms.T
我是一名优秀的程序员,十分优秀!