来自 oData 的 UploadCollection 上传附件无法读取 属性 'bindItems'

UploadCollection upload attachment from oData gives Cannot read property 'bindItems'

我尝试使用片段内的 UploadCollection 从 oData 服务为 Fiori 应用程序上传附件。

片段代码:

<core:FragmentDefinition xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form" xmlns:core="sap.ui.core" xmlns="sap.m"
 xmlns:mvc="sap.ui.core.mvc">
 <UploadCollection id="UploadCollection" maximumFilenameLength="55" multiple="true" change="onChange" fileDeleted="onFileDeleted"
  fileRenamed="onFileRenamed" fileSizeExceed="onFileSizeExceed" items="{/DataAttachment}" typeMissmatch="onTypeMissmatch"
  uploadComplete="onUploadComplete">
  <items>
   <UploadCollectionItem contributor="{contributor}" documentId="{documentId}" fileName="{fileName}" fileSize="{fileSize}"
    mimeType="{mimeType}" thumbnailUrl="{thumbnailUrl}" uploadedDate="{uploadedDate}" enableEdit="{enableEdit}" enableDelete="{enableDelete}"/>
  </items>
 </UploadCollection>
</core:FragmentDefinition>

详细代码:

<IconTabFilter icon="sap-icon://attachment" iconColor="Neutral" design="Horizontal" text="Attachment" key="Attachment">
      <content>
       <core:Fragment id="AttachmentFrag"  fragmentName="ztravel.view.Attachment" type="XML"/>
      </content>
</IconTabFilter>

控制器详细代码:

   var sEntityPath = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZSERVICE/", true);

   // this.setModel(oViewModel);

   // this.getView().bindElement("/DataAttachment");
   
   var oView = this.getView();
   
   // oView.bindElement(sEntityPath);
   // update list binding
   var sAttach = sEntityPath + "/DataAttachment";
   

   var oItemTemplate = new sap.m.UploadCollectionItem({
    documentId: "{Pernr}",
    fileName: "{Reinr}",
    mimeType: "{ImMimeType}",
    thumbnailUrl: "",
    // url: {
    //  parts: [{
    //   path: 'ImImgEqui'
    //  }, {
    //   path: 'ImIdEqui'
    //  }],
    //  formatter: function(idimg, idequi) { 
    //   return oView.getModel().sServiceUrl + "/AttachmentsSet(ImImgEqui='" + idimg + "',ImIdEqui='" + idequi + "')/$value";
    //  }
    // },

    enableEdit: false,
    enableDelete: false,
    visibleDelete: false,
    visibleEdit: false,
    statuses: new sap.m.ObjectStatus({
     title: "Uploaded On",
     text: {
      parts: [{
       path: 'ImDatum'
      }],
      formatter: function(sValue) {
       if (sValue) {
        var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({
         pattern: "dd/MM/yyyy"
        });
        return oDateFormat.format(new Date(sValue));

       } else {
        return sValue;
       }
      }
     }
    })

   });
   
  // var fragmentId = this.getView().createId("AttachmentFrag");
     //       var tab = sap.ui.core.Fragment.byId(fragmentId, "UploadCollection");
       //     tab.bindItems({
   // path: sAttach,
   // template: oItemTemplate
   //});
   
   sap.ui.core.Fragment.byId("AttachmentFrag", "UploadCollection").bindItems({
   path: sAttach,
   template: oItemTemplate
   });

控制台给我这个错误: 类型错误:无法读取未定义的 属性 'bindItems'

关于详细控制器代码的最后部分: sap.ui.core.Fragment.byId("AttachmentFrag", "UploadCollection").bindItems({....

你能帮我解决这个问题吗? 谢谢大家,

小飞

试试这个:

sap.ui.core.Fragment.byId(this.getView().createId("AttachmentFrag"), "UploadCollection")