如何使用节点js从数组中的正文解析器获取数据?

时间:2019-10-31 12:14:21

标签: node.js body-parser

在这里,我有no_of_devices,它在一行中具有三个字段'macAddress','useWith'和'type',该行的数量取决于从select字段中选择的设备数量,所以我在使用body-解析器和我想获取所有具有使用for循环生成的名称的行数据,因此所有具有macAddress的行都将具有name ='macAdd0',name =“ macAdd1”等,其中“ type”和“ useWith”字段也是如此。

HTML

<select id="noOfDevice" class="form-control" name="noOfDevice" onchange="getDeviceCount(this)">
    <option selected value="0">Select</option>
    <option value="1">01</option>
    <option value="2">02</option>
    <option value="3">03</option>
    <option value="4">04</option>
    <option value="5">05</option>
    <option value="6">06</option>
    <option value="7">07</option>
    <option value="8">08</option>
    <option value="9">09</option>
    <option value="10">10</option>
</select>

JavaScript

<script>
    var macAdd;
    var useWith;
    var type;
    var noOfDevice = req.body.noOfDevice;
    for (var i = 0; i < noOfDevice; i++) {
        var k = i.toString();
        macAdd[i] = req.body.macAdd[i];
        useWith[i] = req.body.useWith[i];
        type[i] = req.body.type[i];
        //console.log(req.body.macAdd);
        process.deviceManger(macAdd[i], useWith[i], type[i]);
        console.log('Device' + i + 'Details Update');
    }
    function getDeviceCount(sel) {
        console.log("No of Device:" + sel.value);
        var currCount = sel.value;
        var div = document.createElement("div");
        for (var i = 0; i < currCount; i++) {
            div.setAttribute('id', 'addElements');
            div.innerHTML += '<div class="row"><div class="form-row"><div class="form-group col-md-3"><label for="inputCity">Mac Address</label><input type="text" class="form-control" id="macAdd" name="macAdd' + i + '"></div> <div class="form-group col-md-3"><label for="inputState">Type of Device</label> <select id="inputState" class="form-control" name="deviceType' + i + '"> <option selected>Select</option> <option value="Irys Slate">Irys Slate</option> <option value="Irys Sling">Irys Sling</option> <option value="Irys Swing">Irys Swing</option> </select> </div> <div class="form-group col-md-3"> <label for="inputState">Use with</label> <select id="inputState" class="form-control" name="useWith' + i + '"> <option selected>Select</option> <option value="All">All</option> <option value="Nconnect">Nconnect</option> <option value="Tiara">Tiara</option> <option value="Corona">Corona</option> <option value="TiaraMini">TiaraMini</option> <option value="Nconnect+Tiara">Nconnect+Tiara</option> <option value="Nconnect+Corona">Nconnect+Corona</option> <option value="Nconnect+TiaraMini">Nconnect+TiaraMini</option> </select> </div> </div> </div>';
            document.getElementById("devices").appendChild(div);
        }
    }
</script>

0 个答案:

没有答案