代碼中使用預輸入:Twitter的Typeahead.js在節點JS不獲取建議
<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"}...
)
但是,當我輸入文本中輸入一些東西,不建議生成。
對於可能出現的問題,你有什麼想法嗎?我真的很需要你的幫助。
或者您是否有任何建議在節點使用prefetch
正確執行?
你可以格式化你的代碼,因此它的可讀性更好。 – hgoebl