[英]Javascript reset object inside array
I have the below JS code in my Ember app that gets called; 我在调用的Ember应用程序中具有以下JS代码;
myPanels.accordionPanels = [];
myPanels.accordionPanels.push({
panel: {
name: "my-grid",
type: 'comp',
props: [{
key: 'elementId',
value: "myCustomId"
}]
}
});
So as you can see, I start by setting myPanels.accordionPanels = [] every time and then push the object. 如您所见,我首先设置myPanels.accordionPanels = [],然后推动对象。
However, I got the following error 但是,出现以下错误
Assertion Failed: Attempted to register a view with an id already in use: myCustomId
断言失败:尝试使用已使用的ID注册一个视图:myCustomId
So I am assuming that the object inside is not getting reset & it is able to find the earlier created "myCustomId". 所以我假设里面的对象没有被重置,并且能够找到较早创建的“ myCustomId”。
Am I resetting the array (or rather the object inside it) correctly ? 我是否正确重置数组(或更确切地说是其中的对象)?
Since I am able to push values using: 由于我可以使用以下方法推送值:
accordionPanels = [];
accordionPanels.push({
panel: {
name: "my-grid",
type: 'comp',
props: [{
key: 'elementId',
value: "myCustomId"
}]
}
});
make sure myPanels.accordionPanels doesn't have any prototype associated with it. 确保myPanels.accordionPanels没有任何关联的原型。
Try to inspect its value as: 尝试检查其值为:
myPanels.accordionPanels = [];
console.log(myPanels.accordionPanels); // see if it has values.
You can delete value using : 您可以使用以下方法删除值:
delete myPanels.accordionPanels PROTOTYPE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.