我试图在远程选项中使用typeahead.js 0.9.3 https://github.com/twitter/typeahead,基本上我希望在5-6字段上应用自动完成,并希望根据远程url和value键中当前字段的id添加动态值。
这就是我正在尝试的。
jQuery(function($) {
$( ".posts_autocomplete" ).each(function() {
var fid = $(this).attr("id");
var field = fid.replace("post_", "");
$(this).typeahead({
name: 'posts_search',
remote: '/posts/search?q=%QUERY&field='+field,
valueKey: field,
minLength: 2,
limit: 10
});
});
});我也尝试过替换Bootstrap 3 typeahead.js - remote url attributes,但似乎不起作用。
发布于 2014-03-31 10:10:23
在每次迭代中使用唯一的打字机名称来解析它。
jQuery(function($) {
$( ".posts_autocomplete" ).each(function(i) {
var fid = $(this).attr("id");
var field = fid.replace("post_", "");
$("#"+fid).typeahead({
name: i,
remote: '/posts/search?q=%QUERY&field='+field,
valueKey: field,
minLength: 2,
limit: 10
});
});
});https://stackoverflow.com/questions/22714445
复制相似问题