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