cancel
Showing results for 
Search instead for 
Did you mean: 

Cann't bind list with json model via XML

Former Member
0 Kudos

Hey guys,

I want to use only XML to bind some data in a .json file withe a list. 

Here is my code:

XML View:

<List headerText="Positions" items="{/Positions}">
     <ObjectListItem title="{positions>id}"/>
</List>

index.html

var oPositionsModel = new sap.ui.model.json.JSONModel();
oPositionsModel.loadData("model/Positions.json");
sap.ui.getCore().setModel(oPositionsModel);

model/Positions.json

{ "Positions": [ 
     { "id": 123456, "article": "Abcde", "amount": 12 },
     { "id": 654321, "article": "Edcba", "amount": 21 }
] }

I can't see, what's wrong. But I get "no data" all the time. There is nothing in the console saying there is a problem here.

I hope you can help

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

please see here the answer of nistv4n

http://stackoverflow.com/questions/38117137/sapui5-bindingproblem


And my conlusion:

1. use Component models for View crossed stuff (defined in the Manifest or in the Component.js)

2. use View models for one View stuff

3. don't use Core Models because some other App might use also a Core Model

Answers (3)

Answers (3)

saivellanki
Active Contributor
0 Kudos

Hi Michael,


I tried your code and it works fine for me: Plunker

If still not working for you, try something like this:


onInit: function(){

     var oModel = new sap.ui.model.json.JSONModel();

     oModel.loadData("model/Positions.json");

     oModel.attachRequestCompleted(function(oEvent){

          sap.ui.getCore().setModel(oEvent.getSource());

     })

}

Regards,

Sai.

Former Member
0 Kudos

You talk about adding the onInit to the controller?

Did it and didn't change anything.

saivellanki
Active Contributor
0 Kudos

Strange! Can you debug and see, were you able to get the data in attachRequestCompleted function?

Regards,

Sai Vellanki.

Former Member
0 Kudos

Yes, I do get the data in the attachRequestCompleted function.

Also did sap.ui.getCore().getModel() and got the Model with the array in oData.

saivellanki
Active Contributor
0 Kudos

Check the binding again in this sample: Plunker

Regards,

Sai.

Former Member
0 Kudos

I copy/pasted your index.html and it worked.

Can you tell me, the difference or what is/was wrong with my code.?

saivellanki
Active Contributor
0 Kudos

Just a guess, did you include the following attribute in bootstrap?


data-sap-ui-xx-bindingSyntax="complex"

Regards,

Sai.

Former Member
0 Kudos

Yes, this attribute is in my bootstrap script.

   <script id="sap-ui-bootstrap"
  src="../../resources/sap-ui-core.js"
  data-sap-ui-libs="sap.m,sap.ui.layout"
  data-sap-ui-theme="sap_bluecrystal"
  data-sap-ui-compatVersion="edge"
  data-sap-ui-xx-bindingSyntax="complex"
  data-sap-ui-resourceroots='{"ReviewOrders": ""}'>
  </script>

btw: how do you make you code look like code?

Regards,

Michael

Former Member
0 Kudos

I also tryed:

<Label text="{/Positions}"/>

Positions.json: {"Positions": "hey"}


Not working. So the problem is not with the <List>, the problem is with the binding.

SergioG_TX
Active Contributor
0 Kudos

try the items like this:

<:ObjectListItem title="{id}" />

I don't think you need the extra positions> path in the list item object

Former Member
0 Kudos

Now I have:

  

<List
   headerText="Positions"
   items="{/Positions}">
   <ObjectListItem
   title="{id}">
   </ObjectListItem>
   </List>

but same problem: "no data"

SergioG_TX
Active Contributor
0 Kudos

refresh your browser.. maybe it is still cached?

also,

do you see 2 items in your list but they are just empty?

Former Member
0 Kudos

closed and reopend the browser - same result

I see the no data information.

For me it seems like the <List items="{/Positions}"> binding is not working.?