检查默认选择值标签!
我有一个问题。这是代码!
f.select(:departments,Department.all.collect{|c|[c.name,c.id]},{},:size=>10,:multiple => ture)
class Emergency
has many :departments
end
html源是这样的:
<select id="emergency_departments" multiple="multiple" name="emergency[departments][]" size="10"><option value ="">""</option>....</select>
现在我想获得默认选择的标签,谁能告诉我怎么做?
I have a question.Here is the code!
f.select(:departments,Department.all.collect{|c|[c.name,c.id]},{},:size=>10,:multiple => ture)
class Emergency
has many :departments
end
the html source like this:
<select id="emergency_departments" multiple="multiple" name="emergency[departments][]" size="10"><option value ="">""</option>....</select>
now I want to get the default selected tag , who can tell me how ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想找到所选选项的值吗?是这样吗?
如果是这样,并且您了解一些 JQuery,那么您可以这样做:
You want to find the value of the option selected? Is that right?
If so, and you know your way around a bit of JQuery, this is how you do it:
现在我知道问题了,我使用标签“collection_select”来解决这个问题。它的方法是这样的,
f.collection_select(:部门,部门.all,:id,:名称,)
Now I know the question , i used the tag "collection_select" to solve this problem.Its method like this,
f.collection_select(:departments,Department.all,:id,:name,)