数据的转化
把上面的数据转化为下面的类型
主要的js代码,实现的逻辑自己看
这段代码是一个JavaScript代码片段,主要是对数组进行遍历和操作的过程。下面我会逐步解释这段代码:
首先,创建一个名为 topList 的空数组:let topList = [];
接下来,对 this.interveneStatus.top 数组进行遍历,其中 this.interveneStatus 是一个包含 top 和 block 两个数组的对象。
对于每个 this.interveneStatus.top 数组中的元素 item,执行以下操作:
使用 topList.find 方法查找 topList 数组中是否存在 channelId 等于当前 item 的元素。
如果找到了名为 existingItem 的元素,将当前 item 的 srcid 和 dataId 添加到 existingItem 的 top 数组中。
如果没有找到名为 existingItem 的元素,则创建一个新的对象,包含 channelId 和 top 数组,其中包含当前 item 的 srcid 和 dataId,然后将该对象添加到 topList 数组中。
接下来,对 this.interveneStatus.block 数组进行遍历。
对于每个 this.interveneStatus.block 数组中的元素 item,执行以下操作:
使用 topList.find 方法查找 topList 数组中是否存在 channelId 等于当前 item 的元素。
如果找到了名为 existingItem 的元素,将当前 item 的 srcid 和 dataId 添加到 existingItem 的 block 数组中。
如果没有找到名为 existingItem 的元素,则不执行任何操作。
最后,对 topList 数组中的每个元素 item 进行遍历,对于其中的每个元素,如果 item.channelId 不存在或为假值,则将其设置为 0。
总的来说,这段代码的作用是将 this.interveneStatus.top 和 this.interveneStatus.block 数组中的元素根据其 channelId 值进行合并,最终生成一个新的数组 topList。其中,topList 数组的每个元素包含一个 channelId 和一个 top 数组,top 数组中包含了与该 channelId 对应的 this.interveneStatus.top 数组中的元素的 srcid 和 dataId。此外,如果在 this.interveneStatus.block 数组中找到与某个 channelId 匹配的元素,则将该元素的 srcid 和 dataId 添加到 topList 数组中对应的 block 数组中。最后,对 topList 数组中的每个元素,如果其 channelId 不存在或为假值,则将其设置为 0。