我创建了一个列表,该列表可以通过以下方法删除行:.onDelete(执行:)。
List {
ForEach(itemList.dataLocation) { item in
NavigationLink(destination: ListDetails(name: item.nameDB)) {
ListItem(name: item.nameDB)
}
}
.onDelete(perform: delete)
.onMove(perform: move)
}
func delete(at offsets: IndexSet) {
itemList.dataLocation.remove(atOffsets: offsets)
session.deleteData(id: //id row) //this problem
}
如何将已删除的字符串的值传递给函数?建议仍然从该行获取数据。预先感谢!
答案 0 :(得分:1)
在删除功能中,偏移量是已删除项目的func delete(at offsets: IndexSet) {
for index in offsets {
session.deleteData(id: itemList.dataLocation[index].id) // problem solved
}
itemList.dataLocation.remove(atOffsets: offsets)
}
。通常它将是一个元素的集合。
<div class="input-group">
<div class="col-md-4 mb-3">
<label for="validationServer01">First name</label>
<input type="text" class="form-control is-valid" id="validationServer01" placeholder="First name" value="Mark" required />
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1" />
<label class="custom-control-label" for="customCheck1">Check this custom checkbox</label>
</div>```
.question_box{
border-collapse: collapse;
box-sizing: border-box;
display: table;
height: 72px;
margin-top: 10px;
table-layout: fixed;
width: 100%;
background: rgb(255, 255, 255);
border-width: 1px;
border-style: solid;
border-color: rgb(237, 237, 237);
border-image: initial;
}
.jjyxsP {
background-color: inherit;
color: rgb(33, 102, 216);
font-size: 18px;
font-weight: 600;
text-align: center;
text-transform: uppercase;
border-right: 1px solid rgb(237, 237, 237);
}
.kRyujs {
box-sizing: border-box;
display: table-cell;
height: 100%;
font-family: "Source Sans Pro", sans-serif;
font-size: 14px;
vertical-align: middle;
width: 50px;
overflow: hidden;
padding: 10px;
}
.gpziHh {
display: flex;
flex-direction: row;
-webkit-box-align: center;
align-items: center;
}
.name{
background: transparent;
border: none;
border-bottom: 1px solid #000000;
outline:none;
box-shadow:none;
}
<div class="input-group">
<div class="col-md-4 mb-3">
<label for="validationServer01">First name</label>
<input type="text" class="form-control is-valid" id="validationServer01" placeholder="First name" value="Mark" required />
</div>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck1" />
<label class="custom-control-label" for="customCheck1">Check this custom checkbox</label>
</div>