美文网首页
promise.all 解决 map 遍历 异步问题

promise.all 解决 map 遍历 异步问题

作者: 小马哒哒哒哒哒哒 | 来源:发表于2021-02-23 18:06 被阅读0次
// 字段初始化
    async fieldInit (fields) {
      // 字段 (isFixed: false 非固定字段)
      let newFields = fields.filter(f => !f.isFixed)
      this.form.customFieldList = await Promise.all(newFields.map((item, index) => this.fieldsFormatter(item, index)))
    },
    fieldsFormatter (item, index) {
      return new Promise(async resolve => {
        if (this.drawerTitle === '新建工单') {
          resolve({
            fieldId: item['id'],
            value: this.fieldValueInit(item),
            fieldName: item['name'],
            fieldType: { type: item['type'], label: this.fieldTypeFormatter(item['type']) },
            required: item['required'],
            optional: await this.getOptional(item['id']),
            _index: index
          })
        } else {
          resolve({
            fieldId: item['fieldId'],
            value: this.fieldValueInit(item),
            fieldName: item['fieldName'],
            fieldType: { type: item['fieldType'], label: this.fieldTypeFormatter(item['fieldType']) },
            required: item['required'],
            optional: item['optional'],
            _index: index
          })
        }
      })
    },
promise.all(forEach).png

相关文章

网友评论

      本文标题:promise.all 解决 map 遍历 异步问题

      本文链接:https://www.haomeiwen.com/subject/nehdfltx.html