我有一個陣列@name = ["D2", "D3"]
,所以如何將其設置爲select_tag
作爲選定的選項。用select_tag顯示多個選定的值?
我對這個很努力,但沒有顯示該
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],{
@name.each do |id| :selected =>"#{id}" }), {:multiple => true}
我有一個陣列@name = ["D2", "D3"]
,所以如何將其設置爲select_tag
作爲選定的選項。用select_tag顯示多個選定的值?
我對這個很努力,但沒有顯示該
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],{
@name.each do |id| :selected =>"#{id}" }), {:multiple => true}
你需要的東西是這樣的:
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"], :selected =>["D1","D4"]) , :multiple => true %>
除非你name.id
給你一個「D1」,你可能想改變你的做法。 name
中的哪個字段對應「D1」?
什麼有關:
<%= select_tag "add", options_for_select(["D1","D2","D3","D4"],@name), {:multiple => true} %>
@ user2342350,請注意,所有這些選項都不會有任何'value' [通常不需要] – kiddorails
這是什麼都使用JavaScript或jQuery的呢?請不要噴塗標籤。只使用問題的相關標籤。 –