是否可以使用动态ID作为键来更新数据库?
假设我希望数据库看起来像这样:
- Data
- dynamic key
- data 1
- data 2
该键应该在每次调用databaseRef.updateChildValues(addObject)
时增大。
此外,有没有办法将var设置为键?我已经尝试过了,但是没有用:
var addId: Int = 0
func updateData() {
...
addId += 1
let addObject = [
addId: someData
] as [String: Any]
databaseRef.updateChildValues(addObject)
}
答案 0 :(得分:0)
您可能需要image_path = 'cats-and-dogs/train/dogs/82.jpg'
image = np.expand_dims(ndimage.imread(image_path), 0)
childByAutoId()
答案 1 :(得分:0)
密钥没有增长。这是关键。
如果这就是您的意思,则可以在该键下 下添加其他子节点,但是updateChild值仅在该节点不存在时才添加其他节点。否则它将更新该节点。
此外,如果您想获取新节点的密钥,则可以这样做
buildWorkTracked(data?: ITimecardDet): FormGroup {
// If data was provided, dynamically create the form controls stored in const
// Provide values from data param for inputs
if (data) {
const buildTimecardDetsLineItem = new FormGroup({
payCategory: new FormControl(this.buildPayCategories()),
shiftDifferential: new FormControl(
this.buildShiftDifferentialCategories()
),
overtimeCategory: new FormControl(this.buildOvertimeCategories()),
hoursWorked: new FormControl(data.hours),
earnings: new FormControl({
value: (data.baserate * data.hours).toFixed(2),
disabled: true
})
});
// Patch form array to set selected values based off of data param
buildTimecardDetsLineItem.patchValue({
payCategory: data.paycatinc,
shiftDifferential: data.shiftDifferentialTypeId,
overtimeCategory: data.overtimeTypeId
});
// Return const
return buildTimecardDetsLineItem;
} else {
// If no data provided, create blank form array for end user entry
return new FormGroup({
payCategory: new FormControl(this.buildPayCategories()),
shiftDifferential: new FormControl(
this.buildShiftDifferentialCategories()
),
overtimeCategory: new FormControl(this.buildOvertimeCategories()),
hoursWorked: new FormControl('0:00'),
earnings: new FormControl({ value: null, disabled: true })
});
}
}