生成HTML< select>每个< option>内的标题应用msDropDown插件 [英] generate HTML <select> with title inside each <option> to apply the msDropDown plugin

查看:106
本文介绍了生成HTML< select>每个< option>内的标题应用msDropDown插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 carrierwave 宝石将图片上传到我的应用程序。

现在我需要在一个下拉列表中显示图像,这是一个表单的一部分。

我试图使用 msDropDown 。但是,我需要在我的每个< option> 内生成一个 title =#path for the image < select>

目前我有:

I am using the carrierwave gem to upload images to my application.
Now I need to display the images in a dropdown list that is part of a form.
I am trying to use the msDropDown. However, I need to generate a title="#path for the image" inside each <option> of my <select>.
At the moment I have:

<%= f.select(:style_id, Style.all.map{ |p| [p.dropdown, p.id] }, {:include_blank => 'Select Style | Construction'}, class: "bigselect" ) %>

以上生成以下HTML:

The above generates the following HTML:

<select class="bigselect" id="item_style_id" name="item[style_id]"><option value="">Select Style | Construction</option>
  <option value="1">first</option>
  <option value="2">second</option>
  ...
</select>

我需要编辑我的RoR选择代码以生成下面的HTML。

I need to edit my RoR select code to generate the HTML below.

<select class="bigselect" id="item_style_id" name="item[style_id]"><option value="">Select Style | Construction</option>
  <option value="1" title="#path for the image">first</option>
  <option value="2" title="#path for the image">second</option>
  ...
</select>

图像的 #path是与我选择的下拉列表列相同的模型列 image 所以,使用载波应该像 p.image_url(:thumb)

有关如何生成这个标题的任何想法

非常感谢。

The #path for the image is the column image on the same Model as the dropdown column on my select. So, using carrierwave should be something like p.image_url(:thumb).
Any ideas on how to generate this title?
Many thanks.

推荐答案

尝试将标题作为html选项到< option> 元素

Try to pass title as html options to <option> elements

<%= f.select(:style_id, Style.all.map{|p| [p.name, p.id, :title => p.image_url(:thumb)]}, ....

这篇关于生成HTML&lt; select&gt;每个&lt; option&gt;内的标题应用msDropDown插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆