cancel
Showing results for 
Search instead for 
Did you mean: 

How to check why data binding is not working

former_member184588
Active Participant
0 Kudos

Hi,

I have a json file in my project and would like to bind the data to some controls.

In the onInit function I am using the following code:


onInit : function (evt) {

    // set mock model

    var sPath = jQuery.sap.getModulePath("view.Over", "./../tile_data.json");

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

    this.getView().setModel(oModel);

  },

My View.xml (from SAPUI5 Explored)


<mvc:View

  height="100%"

  controllerName="view.CampOver"

  xmlns:mvc="sap.ui.core.mvc"

  xmlns="sap.m">

  <Page

    showHeader="false"

    enableScrolling="false" >

    <TileContainer

      id="container"

      tileDelete="handleTileDelete"

      tiles="{/TileCollection}">

      <StandardTile

        icon="sap-icon://{icon}"

        type="{type}"

        number="{number}"

        numberUnit="{numberUnit}"

        title="{title}"

        info="{info}"

        infoState="{infoState}" />

    </TileContainer>

    <footer>

      <Toolbar>

        <ToolbarSpacer/>

          <Button text="Edit" press="handleEditPress" />

          <Button text="Busy state" press="handleBusyPress" />

        <ToolbarSpacer/>

      </Toolbar>

    </footer>

  </Page>

</mvc:View>

But when I run the app no tiles occur. I am wondering how to check if the binding is working correct and how to debug the model in order to check if it is filled correct with data?

Thank you,

  Vanessa

Accepted Solutions (0)

Answers (1)

Answers (1)

kedarT
Active Contributor
0 Kudos

Hi Vanessa,

You are missing oModel.loadData("json file path",null,false);


Hope this helps.

former_member184588
Active Participant
0 Kudos

Hi Kedar,

I thought that this would be done within the constructor? I added the loaddata but during the debugging the oModel: Array is still 0.

Any suggestions what to check?

Regards, Vanessa

kedarT
Active Contributor
0 Kudos

Hi Vanessa,

I would do two things:

first in the chrome debugger in the console look type in oModel.getJSON() to see the data.

secondly check the path of the JSON data file and load it specifically using sap.ui.localResources("JSON Model folder name") right before i  create the instance of JSON MODEL.

Hope this helps

former_member184588
Active Participant
0 Kudos

Hi Kedar,

thanks again for your answer. the console displays just an empty array.

I changed my code to:

var oModel = new sap.ui.model.json.JSONModel();
   oModel.loadData("https://webidetestinglqrb3m-s000XXXXXtrial.dispatcher.hanatrial.ondemand.com/tile_data.json");
   this.getView().setModel(oModel);

I changed the url. I can call the url within the browser. But still no result.

Regards, Vanessa

kedarT
Active Contributor
0 Kudos

Is the JSON file not part of your Project?

former_member184588
Active Participant
0 Kudos

Yes, it is part of the project. But I want to avoid problem with the path. Therefore I took the absolute path.

former_member184588
Active Participant
0 Kudos

I entered into the console oModel.loadData("tile_data.json"); and the system answered with undefined

former_member184588
Active Participant
0 Kudos

I have just seen that in the debugger are some PendingRequestHandles. But the getJSON still replies with a "{}". How to process the Requests in order to get the model filled?

kedarT
Active Contributor
0 Kudos

You need to provide the path of the Folder where the file is something like this:

Here TimeEntry is my project name and my loadData for time.json would be oModel.loadData("Model/time.json",null,false);

former_member184588
Active Participant
0 Kudos

Thanks for clearifying this. I wondering about one additional thing. The debugger is staying in the this.getView... line. When I enter this.getView.name in the console the browsers response is "". Could it be that the views name is not set correct and that the binding is not working because of this fact?

former_member184588
Active Participant
0 Kudos

How can I check if the loadData was successfull? How can I check if the file is correct?

kedarT
Active Contributor
0 Kudos

in debugger console.log(oModel) after loadData.

kedarT
Active Contributor
0 Kudos

Just use this.getView() in the console