我的 Ember 应用程序中有以下 JS 代码被调用;
myPanels.accordionPanels = [];
myPanels.accordionPanels.push({
panel: {
name: "my-grid",
type: 'comp',
props: [{
key: 'elementId',
value: "myCustomId"
}]
}
});
正如您所看到的,我每次都首先设置 myPanels.accordionPanels = [],然后推送对象。
但是,我收到以下错误
Assertion Failed: Attempted to register a view with an id already in use: myCustomId
所以我假设里面的对象没有被重置并且它能够找到之前创建的“myCustomId”。
我是否正确重置了数组(或者更确切地说是其中的对象)?
最佳答案
因为我能够使用以下方法推送值:
accordionPanels = [];
accordionPanels.push({
panel: {
name: "my-grid",
type: 'comp',
props: [{
key: 'elementId',
value: "myCustomId"
}]
}
});
确保 myPanels.accordionPanels 没有任何与之关联的原型(prototype)。
尝试检查其值:
myPanels.accordionPanels = [];
console.log(myPanels.accordionPanels); // see if it has values.
您可以使用以下方式删除值:
delete myPanels.accordionPanels PROTOTYPE
关于Javascript重置数组内的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36447185/