gpt4 book ai didi

javascript - AngularFire 0.5 $删除。错误 : Firebase. 子项失败:第一个参数是无效路径

转载 作者:行者123 更新时间:2023-12-02 18:00:16 24 4
gpt4 key购买 nike

这里是 Angular 新手,我有一个 ng-repeat 列表,其中包含 ng-click="remove(item)"按钮,可以触发删除功能:

$scope.remove = function (item) {
console.log(item);
$scope.items.$remove(item);
};

而$scope.items.$remove();非常适合删除模型中的所有项目。我不太清楚为什么如果我传递一个项目进行删除,它会抛出一个错误。以下是我收到的错误。

Error: Firebase.child failed: First argument was an invalid path: "[object Object]". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
at Error (<anonymous>)
at Ga (https://cdn.firebase.com/v0/firebase.js:12:230)
at H.J.F (https://cdn.firebase.com/v0/firebase.js:134:213)
at Object.object.$remove (https://cdn.firebase.com/libs/angularfire/0.5.0/angularfire.js:160:26)
at Scope.MyCtrl.$scope.removeShape (http://127.0.0.1:9000/scripts/controllers/main.js:24:23)
at http://127.0.0.1:9000/bower_components/angular/angular.js:9977:21
at http://127.0.0.1:9000/bower_components/angular/angular.js:17678:17
at Scope.$eval (http://127.0.0.1:9000/bower_components/angular/angular.js:11668:28)
at Scope.$apply (http://127.0.0.1:9000/bower_components/angular/angular.js:11768:23)
at Scope.$delegate.__proto__.$apply (<anonymous>:855:30) angular.js:9193
(anonymous function) angular.js:9193
(anonymous function) angular.js:6746
Scope.$apply angular.js:11770
$delegate.__proto__.$apply VM21684:855
(anonymous function) angular.js:17677
jQuery.event.dispatch jquery-1.9.1.js:3074
elemData.handle

提前感谢您帮助我了解正在发生的事情。

最佳答案

$remove 采用字符串作为参数,即要删除的子项的键名,而不是对象本身。迭代 ng-repeat 中的键和值,这样您就可以访问该键。例如:

<div ng-repeat="(key, item) in items">
<a ng-click="remove(key)">Remove</a>
</div>

关于javascript - AngularFire 0.5 $删除。错误 : Firebase. 子项失败:第一个参数是无效路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20605942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com