即使有更多的行,Typeahead也只显示1行
我试图在我的网站应用程序中实现Typeahead,但到目前为止发现了一些问题。 第一件事是关于我从服务器端发送到前端的logging,即使我得到不止一行,它只显示一行。
我的环境是:
- Node.js的;
- 用Jade模板引擎expression;
- 引导
- MongoDB的。
在服务器端,我添加mongo在输出数组上获取的每一行:
docs.forEach(function(e) { output.push({ _id:e._id, name:e.name, date:e.dates[0].date.toString('dd/MM/yyyy'), type: 'Show', desc:S(e.description).stripTags().s }) });
将它作为JSON发送以提前input:
$('#header-search').typeahead({ remote: '/layoutSearch?value=%QUERY', template: '<table style="width: 400px;"><tr><td><strong>{{name}}</strong></td><td style="float: right">{{date}} - <em>{{type}}</em></td></tr></table>' + '<p style="line-height: 100%; font-size: 11px">{{desc}}</p>' , engine: Hogan, onselect: function(obj) { console.log('Selected: ' + obj); } });
我的“标题search”代码(Jade):
input#header-search.typeahead(type='text', placeholder='Search...', data-provide='typeahead', data-items='4')
find某个地方的“数据项目”,并添加它,但没有任何改变,也“数据提供”,即使名称字段是在typehead选项中指定的。 我的查询是确定的,返回完全的现有文件。
任何build议将非常受欢迎。
我想你需要这个:
valueKey – The key used to access the value of the datum in the datum object. Defaults to value.
所以试试这个:
$('#header-search').typeahead({ remote: '/layoutSearch?value=%QUERY', valueKey: 'name', template: '<table style="width: 400px;"><tr><td><strong>{{name}}</strong></td><td style="float: right">{{date}} - <em>{{type}}</em></td></tr></table>' + '<p style="line-height: 100%; font-size: 11px">{{desc}}</p>' , engine: Hogan, onselect: function(obj) { console.log('Selected: ' + obj); } });
希望能帮助到你!
如果你使用Bloodhound
作为引擎,我认为增加valueKey
并不能解决问题,但是这个解决scheme似乎是可行的:
Typeahead.js / Bloodhound只显示一个结果
这对我有效。
- 如何阅读PassportJS会话数据?
- 无法在nodeJS中validation用户:TypeError:无法使用“in”运算符在fs中search“用户名”
- 将自定义属性添加到Express应用程序和请求。 什么是最好的方法?
- Node.js / Express – 如何获取在path/ index.js app.js中定义的variables?
- Nodejs:Express + RedisStore,req.session未定义
- bookhelfjs中的多个orderBy()列
- Stormpath Express:保存customData
- express.favicon()是做什么的
- 我如何设置node-mongod-native的日志logging?