Rails rjs 替换和交换值
我试图弄清楚如何使用 RJS 在两个字段之间交换...我知道如何替换这些值,但我似乎不知道如何读取它。
是否无法通过 RJS 读取值?只能更换吗?
<%= link_to_function "Swap" do |page|
#to_value = page[:currency_to].value
page[:currency_from].value = to_value
page[:currency_to].value = "test"
end %>
I'm trying to figure out how to use RJS to swap between two fields... i know how to replace the values but I can't seem to figure out how to read it.
Is it not possible to read values thru RJS? Only to replace?
<%= link_to_function "Swap" do |page|
#to_value = page[:currency_to].value
page[:currency_from].value = to_value
page[:currency_to].value = "test"
end %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我测试了以下两项。
或者更好的是,
根据您的 html,您可能需要删除井号符号
I tested both of the following.
or better yet
depending on your html, you may need to remove the pound symbols
我对原型或 rjs 不太了解,但快速浏览一下原型 API 会发现 getValue()。我认为这与
page[:currency_to]
返回原型元素而不是 DOM 元素有关。也许尝试替换
为
Can you just use any javascript you Want in rjs files?我的猜测是否定的,因为它是 Ruby“渲染”Javascript。
我认为您链接到的 Rails API 部分有点误导。它们似乎并不是指实际的“值”,它们只是使用值作为要传递给块的名称。
I don't know much about prototype or rjs, but a quick look at the prototype API shows a getValue(). I would think this has to do with
page[:currency_to]
returning a prototype element as opposed to just a DOM element.Maybe try replacing
with
Can you just use whatever javascript you want in rjs files? My guess is no, since it's Ruby 'rendering' Javascript.
The section of the Rails API you linked to is a bit misleading I think. They don't seem to be referring to an actual 'value', they just use value as the name to be passed to the block.