首页 > 解决方案 > 试图在一次调用中获取 2 个复选框数据以创建 zip 文件。我应该如何在一次服务调用中传递对象中的数组?

问题描述

这是我用单个对象从后端获取对象的地方。

导出函数 downloadFileService(url: string, payload) {

    return new Promise(( reject) => {
      const getHeaders: object = { ...PostHeaders, body: JSON.stringify(payload) }
        fetch(url, getHeaders)
      .then((response) => {
            if (response.ok) {
              const getFileNameFromResponse = response.headers.get("Content-Disposition");
                response.blob()
                    .then((response) => {
                        const fileName = getFileNameFromResponse.split('/').pop();
                        const type = 'application/zip';
                        showXLS(response, fileName, type);
                    });
            } else {
                response
                    .json()
                    .then((json) => {
                        const errors = json;
                        reject(errors ? errors.messageList : []);
                    });
            }
        });

    });
}

我为选中的复选框创建了一个动作,它只是传递一个对象。我想在一个对象中传递一个数组。

export const downloadFormPDF = (dispatch, getState) => {

        const state: IAppState = getState(dispatch);

        state.payrollTaxFormReducerState.checked.forEach(item => {
                const taxFormItem=state.payrollTaxFormReducerState.formCardList[item];
                const downloadPdf= 
                    {selectedCards: taxFormItem.itemID + '~' + taxFormItem.federalId + '~' + taxFormItem.formType + '~' + taxFormItem.year + '~' + taxFormItem.quarter};
                    // itemID:taxFormItem.itemID,
                    // federalId: taxFormItem.federalId,
                    // formType: taxFormItem.formType,
                    // year: taxFormItem.year,
                    // quarter: taxFormItem.quarter



                downloadFileService('/mascsr/wfn/payrollTaxForms/metaservices/taxforms/downloadpdf', downloadPdf);
       console.log("download file", downloadPdf, taxFormItem );
     });






}

标签: javascriptreactjsredux

解决方案


推荐阅读