0
点击删除按钮。我正尝试从我的Firebase数据库中删除特定的子项。我的问题是,我无法参考我的数据库中的特定childByAutoId
,因此我的应用程序不知道要删除的孩子。如何检查自动ID子项下的Firebase中的值?
火力地堡数据库
DataService的文件
import Foundation
import Firebase
import UIKit
let DB_BASE = FIRDatabase.database().reference().child("laboratory") //contains the root of our database
let STORAGE_BASE = FIRStorage.storage().reference()
class DataService {
static let ds = DataService()
//DB References
private var _REF_BASE = DB_BASE
private var _REF_STATION = DB_BASE.child("stations")
private var _REF_USERS = DB_BASE.child("users")
//Storage Reference
private var _REF_ITEM_IMAGE = STORAGE_BASE.child("item-pics")
var REF_BASE: FIRDatabaseReference {
return _REF_BASE
}
var REF_STATION: FIRDatabaseReference {
return _REF_STATION
}
var REF_USERS: FIRDatabaseReference {
return _REF_USERS
}
var REF_ITEM_IMAGES: FIRStorageReference {
return _REF_ITEM_IMAGE
}
//creating a new user into the firebase database
func createFirebaseDBUser(_ uid: String, userData: Dictionary<String, String>) {
REF_USERS.child(uid).updateChildValues(userData)
}
}
,我试图删除这些信息是出了tableViewCell
的。我已经尝试追加到数组的键,但我仍然无法访问适当的子进行删除。
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
return true
}
func tableView(tableView: (UITableView!), commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: (NSIndexPath!)) {
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let currentStation = station.title
let stationRef = DataService.ds.REF_STATION.child(currentStation!)
let inventoryRef = stationRef.child("inventory")
var deleteAction = UITableViewRowAction(style: .default, title: "Delete") {action in
//delete items from firebase
self.items.remove(at: indexPath.row)
tableView.deleteRows(at: [indexPath as IndexPath], with: .fade)
}
var editAction = UITableViewRowAction(style: .normal, title: "Edit") { action in
}
return [deleteAction, editAction]
}
我在网上找不到关于此的信息。提前致谢!
*您*知道哪个孩子你想删除吗?即我想删除一个孩子'favorite_food:'其价值是'披萨'。 – Jay
我想删除整个孩子。例如-KWKZGKMTjwkyjpQtwPn a nd其所有内容 –
基于什么参数?是什么使得该子节点需要被删除?是因为它符合/不符合标准吗?因为它的价值是'披萨'?因为用户刷卡删除它?您需要考虑要删除节点的原因是什么。一旦我们知道了,我们会有一个答案。 – Jay