[英]Trouble with Typeahead.js
我一直在嘗試在我的項目上使用typeahead.js。 我需要來自mysql數據庫的數據。 但是沒有任何建議。 我幾乎嘗試了一切。 這是我的代碼:
HTML文件:
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="js/typeahead.js"></script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Companies: </label>
<input id="tags"/>
</div>
<script>
$('#tags').typeahead({
name: 'tags',
prefetch: 'file.json'
});
</script>
</body>
</html>
file.json
[
{
"value": "Maini Optics",
"tokens": ["Maini","Optics"]
},
{
"value": "Prakash Eyewear",
"tokens": ["Prakash","Eyewear"]
},
{
"value": "Eternity Lifestyles",
"tokens": ["Eternity","Lifestyles"]
},
{
"value": "Aeurole Inspecs",
"tokens": ["Aeurole","Inspecs"]
},
{
"value": "Dynamic Eyewear",
"tokens": ["Dynamic","Eyewear"]
},
{
"value": "abc",
"tokens": ["abc"]
},
{
"value": "Test",
"tokens": ["Test"]
}
]
請幫忙...
PHP(數組中的單個值,即:$ values = array('Maini Optics','Prakash Eyewear')):
$typeahead_data = implode("','", $values);
HTML:
<input type="text" name="name" id="name_typeahead" autocomplete="off" />
<button type="submit" class="btn btn-primary"><i class="icon-search icon-white"></i> Search</button>
JS
$("#name_typeahead").typeahead({
source: ['<?=$typeahead_data;?>'],
items: 20
});
您必須提供姓名
{
"value": "Maini Optics",
"name": "Maini Optics",
"tokens": ["Maini","Optics"]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.