问题描述
我正在尝试从 angular 数组中删除一个元素/最后一个元素。这就是a
的样子
0: {geometry: {…},symbol: {…},attributes: {…},infoTemplate: null,_suspended: false,…}
1: {geometry: {…},attributes: null,infoTemplate: null}
2: {geometry: {…},infoTemplate: null}
这是我的职责
_pushAddOperation: function (a) {
console.log("a",a);
m.forEach(
a,d.hitch(this,function (a) {
var b = a.attributes || {};
b[this._objectIdName] = this._objectIdCounter++;
a.setAttributes(b);
this._graphicslayer.add(a);
if (b === x) {
//deletion
a.splice(-1,1);
}
})
);
}
我收到一条错误消息,说 a.splice 不是函数,我不明白为什么
_pushAddOperation: function (a) {
console.log("a",function (k) {
var b = a.attributes || {};
b[this._objectIdName] = this._objectIdCounter++;
k.setAttributes(b);
this._graphicslayer.add(k);
if (b === x) {
//deletion
k.splice(-1,1);
}
})
);
}
解决方法
您有两个 a
变量,一个在外部函数中,一个在内部函数中。您尝试拼接的 a
似乎是一个对象。不确定,因为我不知道 hitch
方法需要什么。
您正在声明一个函数 _pushAddOperation
,它接收一个名为 a
(数组)的参数,但是您正在声明一个接收名为 a
(对象)的参数的新函数再次。所以你实际上是想对这个对象使用 splice