angularfire,remove方法返回'无效的记录;找不到钥匙“,应该发生什么事? [英] angularfire, remove method returns 'Invalid record; could not find key', what should it be happenning?

查看:131
本文介绍了angularfire,remove方法返回'无效的记录;找不到钥匙“,应该发生什么事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个带有angularjs和firebase的webapp,而我可以保存新的记录,我不能使用someReference删除一条记录。$ remove(varkey);
承诺返回:无效的记录;找不到钥匙,但同样的参考可以正常保存项目。
i修剪varkey的空间,但似乎都失败了,我使用鲍尔依赖关系,哪个版本是angularfire:〜0.8.0根据bower.json



到目前为止,我在我的服务中的代码是:
$ b $ $ p $ 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);});

这是本文的演示基础:,但他们似乎是使用0.5.0版本和即时通讯使用0.8.0。
有什么建议吗?

解决方案

AngularFireArray。$ remove 方法接受一个项目或索引,它不接受一个id。

所以要删除一个你知道id的项目,你必须看项目第一种:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $($ - $ J $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ c>


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);});

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?

解决方案

The AngularFireArray.$remove method accepts either an item or an index, it does not accept an 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆