eth*_*han 5 jquery jquery-ui ruby-on-rails jquery-plugins
我使用rails3-jquery-autocomplete插件,我只是想知道如何使用它来执行多个单词自动完成.
例如INPUT rails,gem它应该生成两次自动列表.
如何解决这个问题呢?..
Tod*_*ddH 14
rails3-jquery-autocomplete现在支持使用data-delimiter选项指定分隔符,因此您不再需要破解它:
f.autocomplete_field:tags,autocomplete_tag_business_path,:"data-delimiter"=>','
我在尝试应用上面的hack时发现它并发现它没有必要.对我来说很棒!
rails3-jquery-autocomplete插件?它似乎不支持多个自动完成,你需要修改插件代码!! 如果您坚持以前的想法,请按照我的步骤操作.
bundle show rails3-jquery-autocomplete以使插件工作directroy修改define_method如下:
define_method("autocomplete_#{object}_#{method}") do
arr = params[:term].split(",")
unless params[:term] && params[:term].empty?
items = object.to_s.camelize.constantize.where(["LOWER(#{method}) LIKE ?", "#{arr[arr.size-1]}%"]).limit(limit).order(order)
else
items = {}
end
render :json => json_for_autocomplete(items, method)
Run Code Online (Sandbox Code Playgroud)
结束
autocomplete-rails.js像这样
修改
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$(document).ready(function(){
$('input[autocomplete]').each(function(i){
$(this).autocomplete({
source: $(this).attr('autocomplete'),
focus: function() {
return false;
},
select: function(event, ui) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(",");
return false;
}
});
});
});
重新启动服务器并尝试
!记住你最好备份autocomplete.rb以避免在运行bundle install后覆盖.
祝好运!
| 归档时间: |
|
| 查看次数: |
2557 次 |
| 最近记录: |