评论

收藏

[jQuery] SAP UI5 文件上传读取xml返回参数

开发技术 开发技术 发布于:2021-12-05 14:06 | 阅读数:515 | 评论:0


try {
    if (file) {
      this._bUploading = true;

      var that = this;
      // var _handleSuccess = function(data) {
      var _handleSuccess = function(event, xhr, settings, data) {
      that.UploadDialog.close();
      var oFileTableModel = that.getView().getModel("MyFile");

      var oFileTableRow = {
        PERNR: "",
        PRE_FILETYPE: "",
        FILENAME_OLD: "",
        FILENAME: "",
        MIMETYPE: "",
        SYUNAME: "",
        SYDATE: "",
        SYTIME: "",
        VALUE: "",
        URL: ""
        },
        oFileTableData;
      if (oFileTableModel != undefined) {
        oFileTableData = oFileTableModel.oData;
      } else {
        oFileTableData = [];
      }

      var oReturnList = event.childNodes[0].children[6]["childNodes"];
      for (var i = 0; i < oReturnList.length; i++) {
        var oNodeName = oReturnList[i].nodeName,
        oNodeValue = oReturnList[i].childNodes[0];

        var oFieldName = oNodeName.split(':')[1];
        switch (oFieldName) {
        case 'PERNR':
          oFileTableRow.PERNR = oNodeValue.data;
          break;
        case 'PRE_FILETYPE':
          oFileTableRow.PRE_FILETYPE = oNodeValue.data;
          break;
        case 'FILENAME':
          oFileTableRow.FILENAME = oNodeValue.data;
          break;
        case 'FILENAME_OLD':
          oFileTableRow.FILENAME_OLD = oNodeValue.data;
          break;
        case 'MIMETYPE':
          oFileTableRow.MIMETYPE = oNodeValue.data;
          break;
        case 'SYUNAME':
          oFileTableRow.SYUNAME = oNodeValue.data;
          break;
        case 'SYDATE':
          oFileTableRow.SYDATE = oNodeValue.data;
          break;
        case 'SYTIME':
          oFileTableRow.SYTIME = oNodeValue.data;
          break;
        case 'VALUE':
          oFileTableRow.VALUE = oNodeValue.data;
          break;
        }
      }
      oFileTableData.push(oFileTableRow);
      that.getView().setModel(new JSONModel(oFileTableData), "MyFile");
      };
      var _handleError = function(data) {
      var errorMsg = '';
      if (data.responseText[1]) {
        errorMsg = /<message>(.*?)<\/message>/.exec(data.responseText)[1];
      } else {
        errorMsg = 'Something bad happened';
      }
      that.fireUploadComplete({
        "response": "Error: " + errorMsg
      });
      that._bUploading = false;
      };

      var oHeaders = {
      "x-csrf-token": this._csrfToken,
      "slug": file.name, //this.changeFileName(),
      "filename_old": file.name,
      "pernr": this.getModel("PersonInfo").oData.PERNR,
      "is_icon": '',
      "FileType": this.oUploadFileType
      };
      jQuery.ajax({
      type: 'POST',
      url: this._url,
      headers: oHeaders,
      cache: false,
      contentType: file.type,
      processData: false,
      data: file,
      success: _handleSuccess,
      error: _handleError
      });
    }
    } catch (oException) {
    jQuery.sap.log.error("导入失败:\n" + oException.message);
    }

关注下面的标签,发现更多相似文章