我正在尝试同时从Firebase数据库中的多个位置删除数据.
在火力地堡文档状态:
"删除数据的最简单方法是在对该数据位置的引用上调用removeValue.您也可以通过将nil指定为另一个写操作(如setValue或updateChildValues)的值来删除.您可以将此技术与updateChildValues一起使用来删除单个API调用中有多个子节点."
我的代码是
let childUpdates = [path1 : nil,
path2 : nil,
path3 : nil,
path4 : nil]
ref.updateChildValues(childUpdates)
Run Code Online (Sandbox Code Playgroud)
所有四个路径都是字符串,但是我收到一个错误:
"没有更多的背景,表达的类型是模棱两可的."
我假设这是因为nil值而发生的,因为如果我用其他任何东西(例如Int)替换nil,则错误消失.
使用updateChildValues从Firebase删除数据的正确方法是什么?我们希望它以与Firebase中的removeValue()函数类似的方式工作.我们更喜欢这样做的原因是因为它可以在一次调用中从多个位置删除.
我正在使用Android Studio尝试将文件写入外部存储.
其他帖子建议我这样做getExternalFilesDir(null),但我收到了消息Cannot resolve method 'getExternalFilesDir(null)'.
public void makeFile() {
try {
String storageState = Environment.getExternalStorageState();
if (storageState.equals(Environment.MEDIA_MOUNTED)) {
File file = new File(getExternalFilesDir(null), "outputFile.txt");
FileOutputStream fos = new FileOutputStream(file);
String text = "Hello, world!";
fos.write(text.getBytes());
fos.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我无法找到任何方法来摆脱这个错误.提前感谢您解决问题的方法.
我们正在尝试收集视图。用户可以在每个单元格中选择一个图像,然后在文本字段中输入文本。我们注意到,在添加四个单元格之后,当我们添加一个新的单元格时,文本字段已经充满了先前单元格中的信息。在我们的代码中,我们永远不会以编程方式填充文本字段(该字段以空开头),我们允许用户执行此操作。有什么建议么?
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Image", forIndexPath: indexPath) as! CollectionViewCell
cell.deleteButton?.addTarget(self, action: #selector(AddNewItem.xButtonPressed(_:)), forControlEvents: UIControlEvents.TouchUpInside)
cell.deleteButton?.layer.setValue(indexPath.row, forKey: "index")
let item = items[indexPath.item]
let path = getDocumentsDirectory().stringByAppendingPathComponent(item.image)
cell.imageView.image = UIImage(contentsOfFile: path)
cell.imageView.layer.borderColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.3).CGColor
cell.imageView.layer.borderWidth = 2
cell.layer.cornerRadius = 7
return cell
}
Run Code Online (Sandbox Code Playgroud) 我有两个数据集:
df1 = pd.DataFrame(data = {'label1': ['A', 'A', 'B', 'C'], 'label2': ['a', 'b', 'c', 'd'], 'value': [1,2,3,4]})
df2 = pd.DataFrame(data = {'label1': ['A', 'A', 'D', 'E'], 'label'2': ['a', 'd', 'c','e'], 'value2': [10,12,23,14]})
Run Code Online (Sandbox Code Playgroud)
我想执行反连接,以便生成的数据框包含 df1 的行,其中在 df2 中找不到键 [['label1', 'label2']] 。
结果 df 应该是:
label1 label2 value
A b 2
B c 3
C d 4
Run Code Online (Sandbox Code Playgroud)
在使用 dplyr 的 R 中,代码将是:
df3 = anti_join(df1, df2, by = c("label1", "label2"))
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助。