我一直在尝试在我的项目中使用 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>
文件.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"]
}
]
请帮忙...