如何动态填充react-awesome-query-builder列表?

a_r*_*red 6 debugging reactjs

我使用以下代码使用数据库中的列表值动态填充react-awesome-query-builder。当我运行此代码并激活下拉菜单时,它说没有数据。

我查看了 JSON 格式,它看起来与 Github 上的示例中的预制配置文件相同(https://github.com/ukrbublik/react-awesome-query-builder)。有什么办法可以动态填充列表吗?如果是这样,有什么明显的问题吗?

const loadMetricConfigFields = async () => {
    let fields = {};

    const result = await FetchData(url);

    // Set up the category fields that will hold the metrics
    result.forEach(element => {
      fields[`${element.categoryName}`] = {
        label: element.categoryName,
        subfields: {},
        tooltip: 'tooltip',
        type: '!struct'
      };
    });

    for (let count = 0; count < result.length; count++) {
      // Set up the subfields first
      fields[`${result[count].categoryName}`]['subfields'][count] = {
        label: result[count].name,
        type: result[count].uiComponentName.toLowerCase(),
        valueSources: ['value', 'field'],
        operators: [],
        fieldSettings: {},
        widgets: {
          field: {},
          number: {
            widgetProps: {}
          },
          rangeSlider: {},
          slider: {}
        },
        mainWidget: 'number',
        defaultOperator: ''
      };

      const operators = await FetchData(url + endpoint + result[count].dataTypeId);

      // Set up the operators for each subfield
      operators.forEach(op => {
        fields[`${result[count].categoryName}`]['subfields'][count]['operators'].push(op.name);
      })

      // Set up the defaultOperator for each subfield
      fields[`${result[count].categoryName}`]['subfields'][count]['defaultOperator'] = operators[0].name;
    }

    await setConfigFields(fields);
  }
Run Code Online (Sandbox Code Playgroud)