【JS】根据A数据获取B数组内容

33 阅读1分钟
async getconf() {
      // 类型映射
      const COLLECTION_TYPE = {
        1: "camera",  // 摄像头
        2: "album"    // 相册
      };
      
      try {
        const { collectionType = [] } = await Promise()
        // 根据配置映射对应的类型
        this.sourceType = collectionType.length > 0
          ? collectionType
              .filter(type => COLLECTION_TYPE[type]) // 过滤有效的类型
              .map(type => COLLECTION_TYPE[type])    // 映射为对应的字符串
          : ["camera"]; // 默认配置
      } catch (error) {
        console.warn("获取配置失败:", error);
        // 出错时使用默认配置
        this.sourceType = ["camera"];
      }
    },