帮助rails collection_select [编辑] [英] Help with rails collection_select [edited]

查看:103
本文介绍了帮助rails collection_select [编辑]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试对我的应用程序实现 jQuery插件.我需要帮助输出这样的东西

I have been trying to implement this jquery plugin to my app.I need help trying to output something like this

<select name="user[university_id]" id="user_university_id" class="selectable">
    <option value="1" title="uni1">Uni1</option>
    <option value="2" title="uni2">Uni2</option>
</select>

通过使用Rails助手...问题是助手似乎从未向选项标签输出title属性..这对于此插件很重要

by using a rails helper...the problem is the helpers never seem to output a title attribute to the option tags.. which is critical for this plugin

请帮助, 预先感谢

我当前的Rails代码是

my current rails code is

<%= f.collection_select(:university_id,University.all,:id,:name) %>

仅输出

<select name="user[university_id]" id="user_university_id">
        <option value="1">Uni1</option>
        <option value="2">Uni2</option>
    </select>

所以基本上,我需要的是将title属性也添加到我的选项中的一种方法.

So basically what I need is a way to also add title attribute to my options.

推荐答案

如果不使用Rails帮助程序路线,则可以使用jQuery添加它:

You could just add it with jQuery, if you don't go the rails helper route:

$(function () {

    $('select.selectable option').each(function () {
        $(this).attr('title', $(this).text());
    });

});

这篇关于帮助rails collection_select [编辑]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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