cancel
Showing results for 
Search instead for 
Did you mean: 

Bind JSON Response to XML List

Former Member
0 Kudos

Hi,

I have an XML view defined as below.


<List id="ticketList" items="{/tickets}" mode="{device>/listMode}"   
   select="handleListSelect">
   <items>
    <ObjectListItem type="{device>/listItemType}" press="onSelect"

     title="{CallRef}">

     <attributes>
      <ObjectAttribute text="{Mestyp}" />
    </attributes>

     <firstStatus>
      <ObjectStatus text="{Status}"
       state="{
       path: 'Status',
       formatter: 'efforttool.util.formatter.ratingState'
      }" />
     </firstStatus>

    </ObjectListItem>

   </items>
  </List>

Now, I am invoking an AJAX call to get some JSON back. I want to be able to bind this JSON to the above list and am having difficulty in doing it.

I can get a variable pointing to the above list using the following code: -

ticketList = sap.ui.getCore().byId("idViewRoot--idViewMaster--ticketList");

But I do not kow what additional code to add to get my JSON respose bound to this list that was defined using an XML view.

Any help is much appreciated.

Thanks

Martin

Accepted Solutions (0)

Answers (1)

Answers (1)

PMarti
Active Participant
0 Kudos

Hi Martin, first you need create a model from json response and then set the model to list. Check this example: JS Bin - Collaborative JavaScript Debugging&lt;/title&gt; &lt;link rel=&quot;alternate&quot; type=&q...

Former Member
0 Kudos

Hi Pau,

I have used this logic to create the model from the return JSON data

ticketModel = new sap.ui.model.json.JSONModel();

 

ticketModel.setData(json);

Now how can I bind this to the XML list that is defined in the view.

As I mentioned earlier I am getting a reference to the list using the following code

 

ticketList = sap.ui.getCore().byId(

"idViewRoot--idViewMaster--ticketList");

I do not know how to bind my model to the list object.

Thanks

Martin

Former Member
0 Kudos

Progress may be being made......

Stand By for further updates.

Thanks for you help so far.

PMarti
Active Participant
0 Kudos

Hi Martin, once you have the model you can put it on the list. For retrieve the list control and do that :

var list = sap.ui.getCore().byId("ticketList");

list.setModel(ticketModel);


Regards,
Pau