0

I try to bind the follwoing json with pattern or formatter:

{
  "d": {
    "__metadata": {
      "id": "http://xxx/sap/opu/odata/sap/ZWM_MDE_SRV_03/BESTSet(Ebeln='45',Lgnum='110')",
      "uri": "xxx/sap/opu/odata/sap/ZWM_MDE_SRV_03/BESTSet(Ebeln='45',Lgnum='110')",
      "type": "ZWM_MDE_SRV_03.BEST"
    },
    "Ebeln": "45",
    "Lgnum": "110",
    "Lgort": "1200",
    "Bestdat": "\/Date(1512086400000)\/",
    "Lfdat": "\/Date(1512086400000)\/",
    "Bktxt": ""
  }
}

If I do like this, it works:

<Text text="{/d/Bestdat}" />

But if I do like this, it shows nothing

<Text text="{ 
  path: '/d/Bestdat',
  type: 'sap.ui.model.type.Date',
  formatOptions: {
    pattern: 'yyyy/MM/dd' 
  }
}" />

Model is bound on the view (not on the form):

var oModel = new sap.ui.model.json.JSONModel(url, true);
this.getView().setModel(oModel);
Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
  • What [tutorials](https://openui5.hana.ondemand.com/#/topic/8b49fc198bf04b2d9800fc37fecbb218) have you already taken from the documentation? What was missing? Why are you using JSONModel for OData? – Boghyon Hoffmann Dec 04 '17 at 09:03
  • i do not use json model. i use the normal SAP-oData-model. but for better presentation I wrote it in json into this post... – Sven Schuberth Dec 04 '17 at 09:06
  • Ok, then we could replace `new sap.ui.model.json.JSONModel` with ODataModel in your question, I guess? – Boghyon Hoffmann Dec 04 '17 at 09:13
  • If you're using v2.ODataModel and `Bestdat` has the type *Edm.DateTime*, you can display the date easily with the binding type [`sap.ui.model.odata.type.DateTime`](https://ui5.sap.com/#/api/sap.ui.model.odata.type.DateTime). Take a look at this answer: https://stackoverflow.com/a/47551731/5846045 – Boghyon Hoffmann Dec 04 '17 at 09:23
  • naa. I was wrong. I'm using json-Model, but the result from SAP is (in standard-call) XML. So I thought it's NOT json. But it is. Excuse me... – Sven Schuberth Dec 04 '17 at 09:28
  • No problem. Regardless of the response format (which can be JSON or XML), switch to [*v2.ODataModel*](https://ui5.sap.com/#/api/sap.ui.model.odata.v2.ODataModel) for the communication between your app and OData service so that you don't have to re-invent the wheel for various common scenarios ;) – Boghyon Hoffmann Dec 07 '17 at 13:02

0 Answers0