我想将对象从变量推入(拼接)到数组中,但这会导致无限循环, 关键是用React状态中的另一个对象替换数组中的对象。
handleDuplicate = (id, nextId) => {
let items = [...this.state.items];
let currentItem = this.state.items[id];
if (items && currentItem) {
console.log(currentItem); // --- logs object from react state properly
for (var i = 0; i < items.length; i++) {
if (items[i].id == nextId) {
items.splice(i, 1);
// items.splice(i, 0, currentItem); // --- causes infinte loop
items.splice(i, 0, { id: 111, test: "test" }); // --- runs ok
i--;
console.log(items);
} else {
console.log("---");
}
}
}
this.setState({ items });
};
答案 0 :(得分:3)
您可以使用Set MyPrime = CreateObject("Scripting.Dictionary")
函数替换该项目:
map