这里有角度的新手,我有一个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
提前感谢您帮助我了解正在发生的事情。
答案 0 :(得分:2)
$remove
将字符串作为参数,要删除的子项的键名,而不是对象本身。迭代两者 ng-repeat中的键和值,这样您就可以访问该键。例如:
<div ng-repeat="(key, item) in items">
<a ng-click="remove(key)">Remove</a>
</div>
答案 1 :(得分:0)
你也可以使用#include <iostream>
#include <cstring>
int main(void)
{
int id = 12;
int age = 14;
const size_t size = sizeof(int);
unsigned char* pData = new unsigned char[2*size];
memcpy(pData,&id,size);/* using memcpy to copy */
pData = pData + size;
memcpy(pData,&age,size);/* using memcpy to copy */
std::cout<<*reinterpret_cast<int*>(pData)<<std::endl;
pData = pData - size;
std::cout<<*reinterpret_cast<int*>(pData)<<std::endl;
delete []pData;
return 0;
}
键中的“build”,你可以在angular ng-repeat中使用它,并将$ index传递给你的remove方法:
$index