我已经对图像中的垃圾空间进行了陈旧的修复。我:after_update_element => "trimSelectedItem"在选项哈希中添加了一个model_auto_completer(这是三个给定的第一个哈希)。然后我trimSelectedItem找到适当的子元素并将其内容用作元素值:
function trimSelectedItem(element, value, hiddenField, modelID) {
    var span = value.down('span.display-text')
    console.log(span)
    var text = span.innerText || span.textContent
    console.log(text)
    element.value = text
}
但是,这会与该:allow_free_text选项发生冲突,如果其中的文本不是列表中的“有效”项目,则默认情况下,一旦文本框失去焦点,该选项就会将文本更改回来。:allow_free_text => true所以我也必须通过传递选项散列(同样是第一个散列)来关闭它。不过,我真的宁愿它继续存在。
所以我目前创建自动完成器的调用是:
<%= model_auto_completer(
    "line_items_info[][name]", "", 
    "line_items_info[][id]", "",
    {:url => formatted_products_path(:js),
     :after_update_element => "trimSelectedItem",
     :allow_free_text => true},
    {:class => 'product-selector'},
    {:method => 'GET',  :param_name => 'q'}) %>
products/index.js.erb 是:
 <ul class='products'>
    <%- for product in @products -%>
    <li id="<%= dom_id(product) %>">
            <%= image_tag image_product_path(product), :alt => "" %>
            <span class='display-text'><%=h product.name %></span>
    </li>
    <%- end -%>
 </ul>