【发布时间】:2020-05-02 18:36:53
【问题描述】:
我想删除带有其 ID (let db = Firestore.firestore()db.collection("Warenkorb").document(i.id).delete()) 的项目。所以这是我的代码。可悲的是,当我删除一个项目时,集合中的所有项目也会被删除。为什么?有人可以帮我吗?
ForEach(cart.data) { i in
HStack{
Image("pic").resizable().scaledToFit().frame(width: 50, height: 75, alignment: .leading).padding().foregroundColor(.black)
Spacer()
VStack(alignment: .leading){
Text(i.name).font(.system(size: 25)).foregroundColor(.black)
HStack{
Text(i.preis).font(.system(size: 20)).foregroundColor(.black)
Text(i.size).font(.system(size: 20)).foregroundColor(.black)
}
}
Spacer()
Text("\(i.quantity)").font(.system(size: 25)).foregroundColor(.black)
Spacer()
if self.remove{
Button(action: {
let db = Firestore.firestore()
db.collection("Warenkorb").document(i.id).delete()
self.show.toggle()
self.show.toggle()
}) {
Image(systemName: "minus.circle.fill")
.resizable()
.frame(width: 20, height: 20)
.foregroundColor(.red)
}
}
Spacer()
}
.background(Color("Color-1")).frame(width: 350, height: 100).cornerRadius(30).padding(.leading)
}
【问题讨论】:
标签: firebase google-cloud-firestore swiftui