js gets the value of table, js gets the value of input in td

1. If you want the table to have an editable function, you can embed the input tag in the table

The function of writing {{ list_one[1] or '' }} is that when the value of list_one[1] is None, the front-end web interface will not display None, but will be displayed as empty
<table class="table table-bordered" id="parameters">
       <tr>
            <th style="width: 5px">变量名称</th>
            <th>变量值</th>
       </tr>
        {% for list_one in info_list[8] %}
       <tr>
             <td>{{ list_one[0] }}</td>
             <td><input class="form-control" placeholder="必填" value="{{ list_one[1] or '' }}"></td>    
       </tr>
       {% endfor %}
</table>

2. How does js get these values ​​and pass them to the flask backend?

The following methods can obtain the value of each row and column of the table.

JSON.stringify(parameters) put the parameter json words

$("#save_script").click(function () {
        var parameters = new Array();
        rows = document.getElementById("dubbo_parameters").rows;
        for(var row=1;row<rows.length;row++){
            parameters[row-1] = new Array();
            for(var col=0;col<rows[row].cells.length;col++){
                if(col%2 == 0){
                    parameters[row-1][col] = rows[row].cells[col].innerHTML;
                }else {
                    parameters[row-1][col] = rows[row].cells[col].childNodes[0].value;
                }
            }
        }
        $("#dubbo_para").val(JSON.stringify(parameters));
       
 });

3. How to get the value passed by the front end in the background

Using flask's json.load method, you can turn the string passed from the front end into a python list

dubbo_para = json.loads(request.form.get("dubbo_para"))

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324695030&siteId=291194637