【发布时间】:2013-12-17 05:52:38
【问题描述】:
用于预输入的代码:
<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在节点中正确实现typeahead有什么建议吗?
【问题讨论】:
-
您可以格式化您的代码,使其更具可读性。
标签: ajax json node.js twitter-typeahead