用于预输入的代码:
<script type="text/javascript">
$('input.typeahead').typeahead({
name: 'Artist',
prefetch:{url: '/queryjson, ttl: '1'},
template: '<p><strong>{{firstname}}</strong>',
limit : 10,
engine: Hogan,
});
</script>
App.js 中的代码:
app.get('/queryjson', function(req,res,next){
var firstname = req.body.firstname;
connection.query("select firstname from entries",
function (err, rows, fields) {
if (err)
throw err;
res.end(JSON.stringify({
data : rows
}));
});
})
最后是 HTML 中输入文本的代码:
<input class="typeahead" type="text" placeholder="Artist" data-provide="typeahead">
注意:
当我queryjson
在地址栏中输入/时,数据库生成的行是可用的,并且是json格式({"data":[{"firstname":"sheila"},{"firstname":"Noreen"}...
)
但是当我在输入文本中输入内容时,不会生成任何建议。
您对可能出现的问题有任何想法吗?我真的,真的需要你的帮助。
或者您对typeahead
in node using的正确实施有什么建议prefetch
吗?