在视图中:
<%= text_field_with_auto_complete :vendor, :number, {}, {:with => "'vendor[number]=' + $('vendor_number').value"} %>
在控制器中:
auto_complete_for :vendor, :number do |vendors, params|
vendors.vendor_company_filter(params[:company_id])
end
工作正常,结果列出了供应商编号 但是我在结果列表中需要“供应商名称+供应商编号”,我该如何实现这一目标? 请帮忙..
答案 0 :(得分:0)
def auto_complete_for_vendor_number
@vendors = Vendor.find_by_number(number)
render :partial => 'auto_complete_for_vendor_number'
end
in _auto_complete_for_vendor_number.html.eb partial:
<ul>
<% @vendors. each do |vendor| %>
<li><%= vendor.name+'('+vendor.number+')' %></li>
<% end %>
</ul>
一切正常:)