将ODataModel转换为JSON模型 [英] Converting ODataModel into JSON Model

查看:120
本文介绍了将ODataModel转换为JSON模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于在读取UI5公用表的所有行时都存在问题,并且表中的getModel()方法提供了一个模型.

Because of problems with reading all lines of a UI5 common table and the getModel() method from table offers a model.

我以为可以用JSONModel代替ODataModel,现在的问题是如何将ODataModel转换为JSONModel.
因为JSON提供了一些双向绑定选项,应该会有所帮助.

I thought I could use a JSONModel instead of my ODataModel, the problem now is how to get the ODataModel to the JSONModel.
Because JSON offers some Two Way Binding options which should be helpful.

我试图读取一些集合并将其绑定到JSONModel,问题是我无法将新模型绑定到两个视图,因为它不提供某些集合.

I tried to read some set and bind it to the JSONModel, the problem is that I couldn't bind the new model two the view because it doesn't offer some set.

这是我的代码的摘要.希望这应该更容易解决,因为它可以读取所有表行:

Here is a snippet of my code. Hopefully this should be easier too fix as the reading all table rows:

//Erstellung des Modells
var oModel2 = new sap.ui.model.odata.ODataModel(url, true, username, password);
var oModel = new JSONModel(jQuery.sap.getModulePath("QuickStartApplication.model", "/Search.json"));

oModel2.setSizeLimit(8000000);
var pspJSONModel = new sap.ui.model.json.JSONModel();
var oODataJSONModelDLSet = new sap.ui.model.json.JSONModel();
var oODataJSONModelProjectSet = new sap.ui.model.json.JSONModel();
var oODataJSONModelPSPset = new sap.ui.model.json.JSONModel();
var debitorJSONModel = new sap.ui.model.json.JSONModel();
this.getView().setModel(pspJSONModel, "jsonmodel2");
this.getView().setModel(oODataJSONModelDLSet, "jsonmodel");
this.getView().setModel(oODataJSONModelProjectSet, "jsonmodel3");
this.getView().setModel(oODataJSONModelPSPset, "jsonmodel4");
this.getView().setModel(debitorJSONModel, "jsonmodel5");
this.getView().setModel(oModel, "saves");
// etc

oModel2.read("/SEARCH_DLSet", null, null, false, function (oData, oResponse) {
    oODataJSONModelDLSet.setData({ DLSet: oData });
});
oModel2.read("/Search_ProjectsSet", null, null, false, function (oData, oResponse) {
    oODataJSONModelProjectSet.setData({ ProjectSet: oData });
});
oModel2.read("/SEARCH_PSPSet", null, null, false, function (oData, oResponse) {
    oODataJSONModelPSPset.setData({ PSPset: oData });
});
oModel2.read("/DebitorSet", null, null, false, function (oData, oResponse) {
    debitorJSONModel.setData({ DebitorSet: oData });
});
oModel2.read("/PSPSet", null, null, false, function (oData, oResponse) {
    pspJSONModel.setData({ Pspset2: oData });
});
var json1 = pspJSONModel.getJSON();
var json2 = oODataJSONModelDLSet.getJSON();

我看到表行绑定找到了应该获取的正确长度的数据,但列绑定不起作用.这是行绑定然后是列的代码段

I saw that the table row binding has found the correct length of the data that it should get but the column binding won't work. Here is a code snippet of row binding and then the column

                            <Text text="PSP(A-Nr.)" class="sapUiResponsiveMargin" ></Text>
                            <ComboBox id="combo1"  items="{path: 'jsonmodel2>/Pspset2/results'}">
                                <core:Item key="{jsonmodel2>Psp}" text="{jsonmodel2>Psp}" />
                            </ComboBox>         

                            <Text text="Abrechnungsstatus" class="sapUiResponsiveMargin" ></Text>
                            <ComboBox id="Abrechnungsstatus"></ComboBox>                    
                        </l:VerticalLayout>
                    </l:HorizontalLayout>
                </l:VerticalLayout> 
             </l:HorizontalLayout> 
             </ScrollContainer> 
         </Panel>   
     <Panel visible="false" height="80%" width="98%" id="__layout15" class="__layout5">
<Button text="Edit" id="edit" type="Transparent" class="buttons" press="onEditRow"> </Button>
        <t:Table class="table0" id="table1" selectionMode="MultiToggle" rows="{jsonmodel>/DLSet/results}">
            <t:columns>
                <t:Column class="columns"  width="105px">
                    <Label text="Kontrakt Nr." id="lKontrakt" >
                    </Label>    
                    <t:template>
                        <commons:TextField id="Kontrakt" editable="false" value="{jsonmodel>KontraktNr}" ></commons:TextField>
                    </t:template>                   
                </t:Column>

我的两个OData模型的第一个绑定属性都在sPath下设置了集合名称,但我的新OData模型却没有此属性.

Also my two OData Models got on first binding property the set name under sPath but my new one won't get this property.

以下是一些调试屏幕:

具有绑定第一属性的OModel 1

具有绑定的第一个属性但没有正确路径的新模型

更新有关json结果外观的示例:
PSPSet:

Update examples of how the json Result looks like:
PSPSet:

{
  "Pspset2": {
    "results": [
      {
        "__metadata": {
          "id": "http://hvw-sapdev01.oms-sap.omnisys.de:8000/sap/opu/odata/SAP/Z_TBRKNPRO_SEARCH_DL_SRV/PSPSet('00014158001')",
          "uri": "http://hvw-sapdev01.oms-sap.omnisys.de:8000/sap/opu/odata/SAP/Z_TBRKNPRO_SEARCH_DL_SRV/PSPSet('00014158001')",
          "type": "Z_TBRKNPRO_SEARCH_DL_SRV.PSP"
        },
        "Psp": "00014158001"
      },
      {
        "__metadata": {
          "id": "http://hvw-sapdev01.oms-sap.omnisys.de:8000/sap/opu/odata/SAP/Z_TBRKNPRO_SEARCH_DL_SRV/PSPSet('00030173001')",
          "uri": "http://hvw-sapdev01.oms-sap.omnisys.de:8000/sap/opu/odata/SAP/Z_TBRKNPRO_SEARCH_DL_SRV/PSPSet('00030173001')",
          "type": "Z_TBRKNPRO_SEARCH_DL_SRV.PSP"
        },
        "Psp": "00030173001"
      }
    ]
  }
}

和DLSet:

{
  "DLSet": {
    "results": [
      {
        "__metadata": {
          "id": "http://hvw-sapdev01.oms-sap.omnisys.de:8000/sap/opu/odata/SAP/Z_TBRKNPRO_SEARCH_DL_SRV/SEARCH_DLSet(9168)",
          "uri": "http://hvw-sapdev01.oms-sap.omnisys.de:8000/sap/opu/odata/SAP/Z_TBRKNPRO_SEARCH_DL_SRV/SEARCH_DLSet(9168)",
          "type": "Z_TBRKNPRO_SEARCH_DL_SRV.SEARCH_DL"
        },
        "Abrechungsstatus": "",
        "Contractnr": "",
        "DatumHigh": "",
        "DatumLow": "",
        "Login": "",
        "Mandant": "",
        "Mitarbeiter": "",
        "Name": "",
        "Psp": "",
        "Client": "001",
        "Id": 9168,
        "Impdate": "",
        "Ldatum": "20130705",
        "Lperiode": "",
        "PersNr": "49056462",
        "PersName": "J",
        "PersGrade": "",
        "LocalGradeKey": "",
        "LocalGradeDesc": "",
        "PersKstN": "",
        "PersKstB": "",
        "AufKstNr": "",
        "AufKstBe": "",
        "AufNr": "",
        "AufBez": "",
        "Bemerkung": "",
        "DebitorId": "0000037503",
        "DebitorBez": "G",
        "ProdCodeNr": "T130",
        "ProdCodeBez": "Allg. Steuerberatung von Unternehmen",
        "IndustCodeNr": "99999",
        "IndustCodeBez": "H",
        "ArbZ": "5.0000000000000000E-01",
        "ScaleRate": "280.0000",
        "MarketRate": "280.0000",
        "ScaleValue": "0.0000",
        "CostRate": "0.0000",
        "CukyCostRt": "",
        "Fakturiert": "",
        "FakeLdate": "",
        "Confidential": "",
        "KontraktNr": "5000059735",
        "PrctrHead": "",
        "Honorar": "140.0000",
        "Kosten": "140.0000",
        "SatzNeu": "280.0000",
        "HonorarNeu": "140.0000"
      },
      {
        "__metadata": {}
      }
    ]
  }
}

推荐答案

由于您的代码似乎还不清楚,因此这里提供了有关如何实现它的指针:

As your code seems really unclear, here's a pointer on how you could implement it:

您将OData响应读入JSONModel:

You read the OData response into a JSONModel:

var oModel2 = new sap.ui.odata.ODataModel();
var oODataJSONModelDLSet = new sap.ui.json.JSONModel();

this.getView().setModel(oODataJSONModelDLSet, "jsonmodel");

// etc

oModel2.read("/SEARCH_DLSet" + filterString, null, null, false, function (oData, oResponse) {
    oODataJSONModelDLSet.setData({ DLSet: oData });
});

...然后绑定到视图:

...you then bind to your view:

<t:Table rows="{jsonmodel>/DLSet/results}">
    <t:columns>
        <t:Column>
            <Label text="Kontrakt Nr." /> 
            <t:template >
                <commons:TextField value="{jsonmodel>KontraktNr}" />
            </t:template>                   
        </t:Column>

根据更新的问题更新答案

Updated answer based on updated question

这篇关于将ODataModel转换为JSON模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆