简体   繁体   English

如何使用jQuery将二维数组值推送到输入字段?

[英]how to push two dimensional array values to input field using jquery?

I have an input field which is displayed a modal with row records while onclick event is fired of each row of the parent table. 我有一个输入字段,在对父表的每一行触发onclick事件时,它会显示具有行记录的模式。

input field is : 输入字段为:

str+=  '<td><input type="text" class="form-control input-sm full-width" data-toggle="modal"  name="bed_selections['+num+']" id="bed_selection'+ num +'" num="'+num+'" onclick="showBedSelection(this)" /></td>';

parent table looks like : 父表如下所示:

在此处输入图片说明

modal looks like : 模态看起来像:

在此处输入图片说明

I need to store these data(sno,confirm) to of this input element bed_selections['+num+'] as an array value for back-end processing. 我需要将这些数据(sno,confirm)存储到此输入元素bed_selections ['+ num +']作为数组值进行后端处理。

How can i achieve this scenario via js/jquery? 如何通过js / jquery实现此方案?

Please tell me your clean solutions. 请告诉我您的干净解决方案。

Create a hidden Input for each row in the table. 为表中的每一行创建一个隐藏的Input。 On modal closing Event get the confirm Check boxes values and put them into an Array. 在模式关闭事件上,获取确认复选框值并将其放入数组。 With Array.join(",") you can serialize Array to string and Update your hidden Input with the corresponding rowid. 使用Array.join(“,”),可以将Array序列化为字符串,并使用相应的rowid更新隐藏的Input。 On your Backend get the hidden Input Value, Split the string into Array using the comma (,) delimeter and you have yourself an Array. 在您的后端上,获取隐藏的输入值,使用逗号(,)分隔符将字符串拆分为Array,然后您便拥有了一个Array。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM