sap.m.UploadCollection不起作用

时间:2015-08-17 12:06:11

标签: javascript sapui5

我尝试根据此example实现UploadCollection。但我不能让它可以运行。

DataMock:

var data = {
"attachments" : [
{
"contributor" : "Susan Baker",
"documentId" : "64469d2f-b3c4-a517-20d6-f91ebf85b9da",
"enableEdit" : true,
"enableDelete" : true,
"fileName" : "Screenshot.jpg",
"fileSize" : 20,
"mimeType" : "image/jpg",
"thumbnailUrl" : "",
"uploadedDate" : "2014-07-30",
"url" : "image/orianda.png"
}, {
"contributor" : "John Smith",
"documentId" : "5082cc4d-da9f-2835-2c0a-8100ed47bcde",
"enableEdit" : true,
"enableDelete" : false,
"fileName" : "Notes.txt",
"fileSize" : 10,
"mimeType" : "text/plain",
"thumbnailUrl" : "",
"uploadedDate" : "2014-08-01",
"url" : "image/orianda.png"
}
]};

Dosen`t work

sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel(), "runtime" )
var oRuntime = sap.ui.getCore().getModel("runtime");
Runtime.setData( data );

和view.xml:

    <UploadCollection id="UploadCollection" maximumFilenameLength="55" multiple="true" change="onChange" fileDeleted="onFileDeleted" fileRenamed="onFileRenamed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch" uploadComplete="onUploadComplete" items="{runtime>/attachments}">
        <items>
            <UploadCollectionItem contributor="{contributor}" documentId="{documentId}" fileName="{fileName}" fileSize="{fileSize}" mimeType="{mimeType}" thumbnailUrl="{thumbnailUrl}" uploadedDate="{uploadedDate}" url="{url}" enableEdit="{enableEdit}" enableDelete="{enableDelete}" /> 
       </items>
            </UploadCollection>

几乎可以工作:

sap.ui.getCore().setModel(new sap.ui.model.json.JSONModel() )
var oRuntime = sap.ui.getCore().getModel();
Runtime.setData( data );

和view.xml:

    <UploadCollection id="UploadCollection" maximumFilenameLength="55" multiple="true" change="onChange" fileDeleted="onFileDeleted" fileRenamed="onFileRenamed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch" uploadComplete="onUploadComplete" items="{/attachments}">
        <items>
            <UploadCollectionItem contributor="{contributor}" documentId="{documentId}" fileName="{fileName}" fileSize="{fileSize}" mimeType="{mimeType}" thumbnailUrl="{thumbnailUrl}" uploadedDate="{uploadedDate}" url="{url}" enableEdit="{enableEdit}" enableDelete="{enableDelete}" /> 
       </items>
            </UploadCollection>

第一个版本加载两个项目,但每个项目的值都为空。

第二个版本正确加载项目。唯一的区别是命名模型

当我尝试上传内容时,两个版本都会抛出错误。

  

无法读取未定义的属性'addEventListener' -

我错了什么?

更新:我想通了;它由模拟服务器引起。rootURI dosent与上传URI一起使用,因此它不应该影响它。 如果有人能证实我这是一个错误,我会打开一个错误报告。

jQuery.sap.require("sap.ui.core.util.MockServer");
var sMockdataBaseUrl = "testdata/data/"
var sMetadataUrl = "testdata/metadata.xml"
sap.ui.core.util.MockServer.config({  
            autoRespond : true,
          autoRespondAfter : 3000
          });
var oMockServer = new sap.ui.core.util.MockServer({
            rootUri : '/server/'
        });

        oMockServer.simulate(sMetadataUrl, {
            'sMockdataBaseUrl' : sMockdataBaseUrl,
            'bGenerateMissingMockData' : true
        });

        oMockServer.start();

1 个答案:

答案 0 :(得分:0)

我复制了这个场景,它完全正常。

这是我试过的例子。

https://github.com/Sarathchandrach/openui5examples/tree/master/UploadCollectionDemo

和我试过的示例代码。

控制器:

var oModel = new sap.ui.model.json.JSONModel(); 
oModel.setData({
    modelData: data
});
this.getView().setModel(oModel, "oAppView");

查看:

<UploadCollection id="UploadCollection" maximumFilenameLength="55" multiple="true" change="onChange" fileDeleted="onFileDeleted" fileRenamed="onFileRenamed" fileSizeExceed="onFileSizeExceed" typeMissmatch="onTypeMissmatch" uploadComplete="onUploadComplete" items="{oAppView>/modelData/attachments}">
    <items>
        <UploadCollectionItem contributor="{oAppView>contributor}" documentId="{oAppView>documentId}" fileName="{oAppView>fileName}" fileSize="{oAppView>fileSize}" mimeType="{oAppView>mimeType}" thumbnailUrl="{oAppView>thumbnailUrl}" uploadedDate="{oAppView>uploadedDate}" url="{oAppView>url}" enableEdit="{oAppView>enableEdit}" enableDelete="{oAppView>enableDelete}" /> 
   </items>
</UploadCollection>