在隐藏的字段数组中添加和删除值 [英] Add and Remove values in a hidden field array

查看:114
本文介绍了在隐藏的字段数组中添加和删除值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I don't understand pretty well how the hidden fields arrays  work,  I have this input:

我不明白隐藏字段数组是如何工作的。 =hiddenid =ftpIds []value =/>

<input type="hidden" id="ftpIds[]" value=""/>

如何在Jquery / Javascript中向数组中添加和删除值?
我有这样的东西:

How can I add and remove values to and from that array in Jquery/Javascript? I have something like this:

$(document).ready(function() {
$('#button').click(function(){
  var ids=$("#txtIds").val();
  $("#ftpIds").addToArray(ids);
 });
   });

并删除我是否需要类似这样的内容?

and to remove do I need something like this?

$("#ftpIds").removeFromArray('3');

我想将一个列表传递给Grails中的Controller,所以我想要一个列表或名为ftpIds的数组。这样对吗?或者这是更好的方式来做到这一点?

I want to pass a list to a Controller in Grails, so I want to have like a list or array named ftpIds. Is it right? or Is this the better way to do this?

推荐答案

正如我在我的评论中所说,这个链接可能会帮助你很多: JSFiddle

As I said in my comment, this link will probably help you a lot: JSFiddle

提交后,在你的控制器,split()方法将帮助你将你的String转换为一个String数组。

After the submit, in your controller, the split() method will help you to convert your String to an array of String.

例如:

For example:

def myList = params.myInput.split(',')

我想(不确定)您需要为您添加一个名称输入,以便使用参数范围(如< input type =hiddenname =myInput/> )。

And I think (not sure) that you need to add a name for you input, in order to use the params scope (like <input type="hidden" name="myInput" />).

这篇关于在隐藏的字段数组中添加和删除值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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