如何在Java脚本中通过二维循环创建数组对象

问题描述 投票:-1回答:1

我有输入,两个选择是通过单击按钮创建的,其增量ID如id =“ commodity0”,id =“ commodity1”,id =“ commodity2”

我想将所有数据发送到一个包含输入的ID的一部分(例如“商品”)作为子主数组,并且此数组在其中包含嵌套的数组,其余输入ID []

如下一般概念

data = [
     commodity = [
         "0" : " value "
         "1" : " value "
         "2" : " value "
     ],
     price = [
         "0" : " value "
         "1" : " value "
         "2" : " value "
     ],
]

我想执行此代码

var arr = ['commodity','price','packages_count','packages_type','gross_weight','net_weight','gunit','nunit'];
var data = [];
for (var n in arr){
    model.find('input[id*='+ arr[n] +'] , select[id*='+ arr[n] +']').each(function () {

        var key = $(this).attr('id').match(/[0-9]+/)[0];
        var val = $(this).val();

       **--thanks for complete code from here** 

    });
}

谢谢您的帮助。

我有输入和由按钮创建的两个选择,单击它们后会获得增量ID,例如id =“ commodity0”,id =“ commodity1”,id =“ commodity2”,我想在一个数组中发送包含ID的一部分的所有数据(例如“。 ..

javascript arrays for-loop nested-loops associative-array
1个回答
0
投票

首先,您提供的Array(预期)不是有效的JavaScript数组。无论如何,尝试这样的事情,也许这就是您想要的:

© www.soinside.com 2019 - 2024. All rights reserved.