如何在表单提交上形成一个输入数组

时间:2017-08-03 06:37:11

标签: javascript jquery html

我想创建一个可以按以下格式提交值的表单

[
   {
       "_id": "59817f39808768495728ae94",
       "updatedAt": "2017-08-02T07:33:00.578Z",
       "createdAt": "2017-08-02T07:28:57.310Z",
       "farmId": "tesform",
       "farmName": "tesform",
       "gatewayId": "123",
       "gatewayName": "testform getway",
       "userId": "abc@kisanraja.com",
       "description": "test details 1st time",           
       "nodes": [
           {
               "permanentAddress": "",
               "description": "with temparature",
               "name": "Node 1",
               "_id": "5981802c808768495728ae9b",
               "sensors": [
                   {
                       "units": "C",
                       "max": 60,
                       "min": -6,
                       "name": "temparature",
                       "_id": "5981802c808768495728ae9c"
                   }
               ],
               "shortAddress": 0
           },
           {
               "permanentAddress": "",
               "description": "with soil moisture and voltage",
               "name": "Node 2",
               "_id": "5981802c808768495728ae98",
               "sensors": [
                   {
                       "units": "C",
                       "max": 60,
                       "min": -6,
                       "name": "moisture",
                       "_id": "5981802c808768495728ae9a"
                   },
                   {
                       "units": "C",
                       "max": 60,
                       "min": -6,
                       "name": "voltage",
                       "_id": "5981802c808768495728ae99"
                   }
               ],
               "shortAddress": 0
           }
       ]
   }
]

我想使用jquery动态创建节点和传感器。每个服务器场应该有多个节点,每个节点可能有多个传感器。

1 个答案:

答案 0 :(得分:0)

您可以将不同的类名称添加到不同的级别输入,然后每个级别输入,当跨越节点时,将节点添加到对象,当传递到传感器时,然后在提交时将传感器添加到数组作为节点对象的属性命名为传感器形式:

 $("#form").submit(function() {
  //deal with them;

});