我想编写代码来从数据库中删除用户。这是代码(我使用的两种方法):
[W 06:54:04.215 NotebookApp] The signatures database cannot be opened; maybe it is corrupted or encrypted. You may need to rerun your notebooks to ensure that they are trusted to run Javascript. The old signatures database has been renamed to /home/aulon/.local/share/jupyter/nbsignatures.db.bak and a new one has been created.
[E 06:54:04.218 NotebookApp] Unhandled error in API request
Traceback (most recent call last):
File "/home/aulon/.local/lib/python2.7/site-packages/notebook/base/handlers.py", line 516, in wrapper
result = yield gen.maybe_future(method(self, *args, **kwargs))
File "/home/aulon/.local/lib/python2.7/site-packages/tornado/gen.py", line 1055, in run
value = future.result()
File "/home/aulon/.local/lib/python2.7/site-packages/tornado/concurrent.py", line 238, in result
raise_exc_info(self._exc_info)
File "/home/aulon/.local/lib/python2.7/site-packages/tornado/gen.py", line 307, in wrapper
yielded = next(result)
File "/home/aulon/.local/lib/python2.7/site-packages/notebook/services/contents/handlers.py", line 124, in get
path=path, type=type, format=format, content=content,
File "/home/aulon/.local/lib/python2.7/site-packages/notebook/services/contents/filemanager.py", line 384, in get
model = self._notebook_model(path, content=content)
File "/home/aulon/.local/lib/python2.7/site-packages/notebook/services/contents/filemanager.py", line 344, in _notebook_model
self.mark_trusted_cells(nb, path)
File "/home/aulon/.local/lib/python2.7/site-packages/notebook/services/contents/manager.py", line 456, in mark_trusted_cells
trusted = self.notary.check_signature(nb)
File "/home/aulon/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 556, in __get__
return self.get(obj, cls)
File "/home/aulon/.local/lib/python2.7/site-packages/traitlets/traitlets.py", line 535, in get
value = self._validate(obj, dynamic_default())
File "/home/aulon/.local/lib/python2.7/site-packages/notebook/services/contents/manager.py", line 58, in _notary_default
return sign.NotebookNotary(parent=self)
File "/home/aulon/.local/lib/python2.7/site-packages/nbformat/sign.py", line 390, in __init__
self.store = self.store_factory()
File "/home/aulon/.local/lib/python2.7/site-packages/nbformat/sign.py", line 338, in factory
return SQLiteSignatureStore(self.db_file)
File "/home/aulon/.local/lib/python2.7/site-packages/nbformat/sign.py", line 147, in __init__
self.db = self._connect_db(db_file)
File "/home/aulon/.local/lib/python2.7/site-packages/nbformat/sign.py", line 171, in _connect_db
os.rename(db_file, old_db_location)
OSError: [Errno 2] No such file or directory
...
我面临的问题是:
2.当我使用'orderByChild'时,我需要将变量'email'传递给它中的'equalTo()',它在某种程度上是不接受的。
如何解决这些问题?请帮忙!
答案 0 :(得分:1)
您有命名冲突:
handler: function(email) <--- Here
{
console.log(email);
this.deleteUser(email);
}
处理程序传回了有关警报中输入的数据,但没有。警报所处的功能已经保留了email
。只需删除email
内的handler
参数即可解决所有问题。
goToDeleteUser(email)
{
console.log(email);
let confirm = this.alertCtrl.create({
title: 'Are you sure you want to delete this user ?',
buttons: [
{
text: 'Delete',
handler: function() <--- remove email has parameter
{
console.log(email);
this.deleteUser(email);
}
}]
});
confirm.present();
}
deleteUser(email)
{
console.log(email);
var userid;
firebase.database().ref().child('users').orderByChild('email').equalTo(email).on("child_added",(snapshot)=>{
userid=snapshot.val().uid}) ;
console.log(userid);
firebase.database().ref('users/userid').remove();
}