简体   繁体   English

html中用于生成按钮的唯一ID

[英]Unique ID in html for generating Buttons

sorry if the title is misleading. 如果标题有误导性,对不起。

I'm having the following problem. 我遇到以下问题。 I am creating multiple rows in HTML using Genshi. 我正在使用Genshi在HTML中创建多行。 For each row I have a button at the end of the row for delete purposes. 对于每一行,我在该行的末尾都有一个用于删除目的的按钮。

The code looks like this: 代码如下:

<form action="/deleteAusleihe" method="post">      
<table>
  <tr>
    <th>ID</th>
    <th>Person</th>
    <th>Buch</th>
    <th></th>
  </tr>

<tr py:for="v in verleihen">
  <input type = "hidden" value="v.id" name="toDelete"/>
          <td py:content="v.id">Vorname der Person</td>
          <td py:content="v.kundeID">Name der Person</td>
          <td py:content="v.buchID">Straße der Person</td>
          <td>
          <input type="submit" name="submit" value="Löschen"/>
          </td>
          <br/>  
</tr>
</table>
</form>

The input type ="hidden" should store the value of each id so I am able to identify the row later on. 输入类型=“ hidden”应该存储每个id的值,以便稍后能够标识该行。

When I try to delete now, and lets assume I have 2 rows filled, I get 2 id's as a paramater, which is logical to me, but I don't know how to solve it. 当我尝试立即删除并假设我填充了2行时,我得到2个id作为参数,这对我来说是合乎逻辑的,但我不知道如何解决。

The deleteAusleihe function looks like this: deleteAusleihe函数如下所示:

@expose()
def deleteAusleihe(self,toDelete,submit):
    Verleih1 = DBSession.query(Verleih).filter_by(id=toDelete)
    for v in Verleih1:
        DBSession.delete(v)
        DBSession.flush()
        transaction.commit()
    redirect("/Verleih")

Thanks in advance for your help! 在此先感谢您的帮助!

The issue is that all the hidden inputs inside the <form> element get submitted at once. 问题是<form>元素内的所有隐藏输入都立即提交。

There are various ways you could solve this. 您可以通过多种方式解决此问题。 Probably the easiest would be to move the form tag inside the loop, so that there are multiple forms and each one only wraps a single input and button. 可能最简单的方法是在循环内移动form标签,以便有多个表单,每个表单仅包装一个输入和一个按钮。

<table>
  <tr>
    <th>ID</th>
    <th>Person</th>
    <th>Buch</th>
    <th></th>
  </tr>

<tr py:for="v in verleihen">
<form action="/deleteAusleihe" method="post"> 
  <input type = "hidden" value="v.id" name="toDelete"/>
          <td py:content="v.id">Vorname der Person</td>
          <td py:content="v.kundeID">Name der Person</td>
          <td py:content="v.buchID">Straße der Person</td>
          <td>
          <input type="submit" name="submit" value="Löschen"/>
          </td>
          <br/>  
</form>
</tr>
</table>
</form>

Here is the code. 这是代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM