fix: use filter to replace find

This commit is contained in:
Cindy Chang
2024-08-15 14:36:59 +08:00
parent 305771ce5a
commit 772302d079

View File

@@ -417,9 +417,8 @@ export default {
const activityNodeArray = nodes.filter(node => node.data.type === 'activity');
// 找出除了 start, end 以外所有的 node 的 option value
activityNodeArray.map(node => nodeOptionArr.push(node.data[this.dataLayerType][this.dataLayerOption]));
// 刪掉重複的元素,將node的option值從小到大排序(映對色階淺到深)
nodeOptionArr = [...new Set(nodeOptionArr)].sort((a, b) => a - b);
// 將node的option值從小到大排序(映對色階淺到深)
nodeOptionArr = nodeOptionArr.sort((a, b) => a - b);
for(let i = 0; i < ImgCapsules.length; i++) {
const startIdx = i * groupSize;
const endIdx = (i === ImgCapsules.length - 1) ? activityNodeArray.length : startIdx + groupSize;
@@ -427,14 +426,16 @@ export default {
}
for(let level = 0; level < leveledGroups.length; level++) {
leveledGroups[level].map(option => {
const curNode = activityNodeArray.find(activityNode => activityNode.data[this.dataLayerType][this.dataLayerOption] === option);
curNode.data = {
...curNode.data,
nodeImageUrl: ImgCapsules[level],
}
})
}
// 考慮可能有名次一樣的情形
const curNodes = activityNodeArray.filter(activityNode => activityNode.data[this.dataLayerType][this.dataLayerOption] === option);
curNodes.map(curNode => {
curNode.data = {
...curNode.data,
nodeImageUrl: ImgCapsules[level],
};
});
});
}
},
},
async created() {