angularfire,remove 方法返回“无效记录;找不到钥匙',它应该发生什么? [英] angularfire, remove method returns 'Invalid record; could not find key', what should it be happenning?
问题描述
我目前正在使用 angularjs 和 firebase 开发一个 web 应用程序,虽然我能够保存新记录,但我无法使用 someReference.$remove(varkey); 删除记录;承诺返回:'无效记录;找不到密钥'但相同的参考能够正常保存项目.我修剪了 varkey 上的空格,但似乎一切都失败了,我正在使用 bower 依赖项,版本为angularfire":~0.8.0"根据 bower.json
I'm currently developing a webapp with angularjs and firebase, while I am able to save new records I am not able to remove a record using someReference.$remove(varkey); the promise returns: 'Invalid record; could not find key' but the same reference is able to save items normally. i trim spaces on the varkey but yet all seems to fail, I'm using bower dependency which version is "angularfire": "~0.8.0" according to bower.json
到目前为止,我的服务中的代码是:
So far my code in my service is:
var testRef = new Firebase('https://test-list.firebaseio-demo.com/list'),
testRefArr = $firebase(testRef).$asArray();
console.log(testRefArr);
var testpromise = testRefArr.$remove('-JXdmpQbeCAEBl7I3YVO');
testpromise.then(function (response) {console.log(response);}, function (error) {console.log('err: '+error);});
这是这篇文章的演示基础:带有 AngularFire 0.5.0 的 AngularJS - $remove item 不起作用但他们似乎使用的是 0.5.0 版本,而我使用的是 0.8.0.有什么想法吗?
this is a demo base from this post: AngularJS with AngularFire 0.5.0 - $remove item doesn't work but they seem to be using version 0.5.0 and im using 0.8.0. Any ideas?
推荐答案
AngularFireArray.$remove
方法接受项或索引,不接受 id.
The AngularFireArray.$remove
method accepts either an item or an index, it does not accept an id.
因此要删除您知道 id 的项目,您必须先查找该项目:
So to remove an item for which you know the id, you have to look the item up first:
testRefArr.$remove(testRefArr.$getRecord('-JXdmpQbeCAEBl7I3YVO'))
这篇关于angularfire,remove 方法返回“无效记录;找不到钥匙',它应该发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!