ils上的ruby中使用javascript获取datetime

ils上的ruby中使用javascript获取datetime

本文介绍了如何在rails上的ruby中使用javascript获取datetime_select字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以前的问题触动了这个话题(),但是我稍微深入一点,意识到我的问题是datetime_select方法。 / p>

我有一个带onchange的文本框。在onchange中,当我将ajax调用到我的控制器时,我需要获取datetime_select字段的值作为参数传递。首先要注意的是,datetime_select实际上由五个下拉列表(年,月,日,时,分)组成,所以我需要分别获取每个下拉列表的值(我猜想,是否有更简单的方法?) 。但是,当我尝试通过以下代码获取他们的价值:

  $(model +'_'+ attribute +'_3i')应该返回day下拉列表的值,我得到一个错误:TypeError:$$ $ $ $ $ $ $ $ $ $ $ $ $ $ $(model_attribute_3i)。value.toS不是函数



如果我手动创建datetime对象的所有下拉列表,同样的调用工作正常。所以似乎有一些魔术,datetime_select的组合方式阻止我询问下拉列表的值。有没有办法解决这个问题,或者我只需要在我的应用程序中重新编码datetime_select功能?

解决方案

现在解决,问题是我是一个javascript n00b ...显然我在太多的地方使用了相同的变量名,导致了奇怪的行为。


I had a previous question that touched this topic (Rails: how to get value from another field when executing an onchange remote function in textfield), but then I dugg a little deeper and realized that my problem is the datetime_select method.

I have a textfield with onchange. In the onchange I need to get the value of a datetime_select field to pass as a parameter when making the ajax call to my controller. The first thing to note is that a datetime_select is actually composed of five dropdowns (year, month, day, hour and minute), so I need to get the values of each of them separately (I presume, is there a simpler way?). But when I try to get their value with code like:

$(model + '_' + attribute + '_3i').value

which should return the value of the "day" dropdown I get an error: "TypeError: $("model_attribute_3i").value.toS is not a function"

If I create all the dropdowns for the datetime objects manually the same call works just fine. So there seems to be some magic in the way a datetime_select is composed that prevents me from asking the value of the dropdowns. Is there any way to go around this or do I just have to recode the datetime_select functionality in my application?

解决方案

Problem seems to be solved for now, problem was me being a javascript n00b... apparently I used same variable names in too many places which leaded to weird behavior.

这篇关于如何在rails上的ruby中使用javascript获取datetime_select字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:11