首页 > 解决方案 > 如何将选定表行中的值传递到我的后端

问题描述

在我的index.html页面中,我有一个表格行:

<tr role="row" class="odd" style="color: rgb(0, 0, 0);">
                <td hidden="" class="sorting_1">6</td>
                <td>example_name</td>
                <td>example_phone</td>
                <td>example_email</td>
              </tr>

index.html 中的表是使用 bootstrap 4 和 MDBootstrap 呈现的。

在浏览器中选择行后,<tr>该类将其状态更改为tr-color-selected

<tr role="row" class="odd tr-color-selected" style="color: rgb(0, 0, 0);">
                <td hidden="" class="sorting_1">6</td>
                <td>example_name</td>
                <td>example_phone</td>
                <td>example_email</td>
              </tr>

如何example_name, example_phone, example_email将所选表格行的值传递给我的控制器views.py?我在后端使用 Flask 和 SQLAlchemy。


编辑 #1 - 服务器端 javascript 代码

我正在使用 MDBootstrap 模态编辑器 ( https://mdbootstrap.com/docs/b4/jquery/plugins/table-editor/ ) 来呈现我的数据表:

<script>
  $('#persons_table').mdbEditor({
  modalEditor: true,
  headerLength: 6,
  });
  $('.dataTables_length').addClass('bs-select');
</script>

这是我生成表格的代码:

<!-- table -->
        <table id="persons_table" class="table table-sm table-striped table-bordered" cellspacing="0" width="100%">
          <thead>
            <tr>
              <th hidden class="th-sm">ID
              </th>
              <th class="th-sm">example_name
              </th>
              <th class="th-sm">example_phone
              </th>
              <th class="th-sm">example_email
              </th>
            </tr>
          </thead>
          <tbody>
              {% for row in persons %}
              <tr>
                <td hidden>{{row.id}}</td>
                <td>{{row.example_name}}</td>
                <td>{{row.example_phone}}</td>
                <td>{{row.example_email}}</td>
              </tr>
            {%- endfor %}
            </tbody>
        </table>
      </div>
    </div>

标签: pythonhtmltwitter-bootstrapflasksqlalchemy

解决方案


推荐阅读