Html 将select转换为在rails中选择_标记
有没有办法将select转换为该语句的select标记:Html 将select转换为在rails中选择_标记,html,ruby-on-rails,ruby,select,ruby-on-rails-4,Html,Ruby On Rails,Ruby,Select,Ruby On Rails 4,有没有办法将select转换为该语句的select标记: <%= select "invoice_product_code", @invoice_product_array.each_with_index.map { |jsondata, index| [jsondata["invoice_product_code"], index]}, {:selected => item["inv
<%= select "invoice_product_code",
@invoice_product_array.each_with_index.map {
|jsondata, index|
[jsondata["invoice_product_code"],
index]},
{:selected => item["invoice_product_code"]},
:style => "width:110px"
%>
赤裸裸地
我想从数组中定义每个选项值和选项文本
选定选项
风格
就像上面所说的
这是生成的HTML:
<select id="invoice_product_code_invoice_product_code" name="invoice_product_code[invoice_product_code]" style="width:110px"><option value="0">INVPRODA</option>
<option value="1">INVPRODB</option>
<option selected="selected" value="2">INVPRODC</option>
<option value="3">INVPRODD</option>
<option value="4">INVPRODE</option>
<option value="5">INVPRODF</option>
<option value="6">INVPRODG</option></select>
我觉得这是不可能的。无法从API中找到合适的示例
这不起作用:
<%= select_tag "invoice_product_code",
@invoice_product_array.each_with_index.map {
|jsondata, index|
[jsondata["invoice_product_code"],
index]}
%>
但这不起作用:
它的格式正确,因为value和display文本是json字符串,而不是数组项中的特定键值
<%= select_tag "invoice_product_code",
options_for_select(@invoice_product_array)
%>
选项\u for\u select使用一个额外的参数来指定所选的值,并且每个选项都可以将HTML属性作为最后一个元素
<%= select_tag "invoice_product_code", options_for_select(
@invoice_product_array.each_with_index.map {
|jsondata, index|
[jsondata["invoice_product_code"],
index,
style: 'width: 110px;']},
item["invoice_product_code"])
%>