【问题标题】:SwiftUI, List, .onDelete(perform: ) and FirestoreSwiftUI、List、.onDelete(perform:) 和 Firestore
【发布时间】:2020-03-18 07:26:47
【问题描述】:

我创建了一个能够通过以下方法删除行的列表:.onDelete (perform:)。

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
}

如何将已删除字符串的值传递给函数?建议仍从该行获取数据。提前致谢!

【问题讨论】:

  • 如果没有弄错,IndexSet 有返回第一行的属性

标签: google-cloud-firestore swiftui


【解决方案1】:

在删除函数中,offsets 是被删除项目的IndexSet。通常它是一组一个元素。

func delete(at offsets: IndexSet) {
  for index in offsets {
    session.deleteData(id: itemList.dataLocation[index].id) // problem solved
  }
  itemList.dataLocation.remove(atOffsets: offsets)
}

【讨论】:

    猜你喜欢
    • 2020-11-06
    • 2020-01-03
    • 1970-01-01
    • 2021-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多