0
votes

I try to fix this for several hours but cann't see my mistake. I try to do just a simple binding:

in my index.html

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

...

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

in my App.view.xml

...
<Page title="{/greeting}">
...

data.json

{
"greeting": "hey"
}

I cannot see what's wrong here. Even a sap.ui.getCore().getModel() during debugging gives me a Object with {"greeting":"hey"} in it's oData variable.

I hope you guys can help.

I also posted here the original question. But since I simplified it, I should post this in a seperate question. Binding in List with XML

--------- update --------

this.getView().setModel(oModel); -> works

sap.ui.getCore().setModel(oModel); -> doesn't work

2

2 Answers

0
votes

I think you meant to use an absolute binding path in your application. This means that you will have to prefix it with a slash:

<Page title="{/greeting}">

You can find more about the binding path syntax for JSON models here: http://help.sap.com/saphelp_hanaplatform/helpdata/en/d5/2e364907f94a3caeb4f5e5ad0cf302/content.htm

Another thing I noticed is that you declare oModel, but load your data into oPositoModelionsModel. I think you intended to load your data into oModel instead:

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

The rest of the code seems very legit. Have a look at this jsbin in which I have modified your code slightly, so that it pulls data from the the Star Wars API.

If the Model is not inherited from core to your view, the inheritance link may be broken somewhere. This happens in e.g. dialog boxes. Dialogs are not added to the UI tree, but the addDependent method will still connect the dialog to the lifecycle management and data binding of underlying UI component (e.g. view). You can read more about this in Step 16 of the UI5 walk-through.

0
votes

If you assign your model to the global namespace of the application (sap.ui.getCore().setModel()), the model should automatically bound to the views. You can bind them to the view (or the page itself) directly.

It's recommended to assign models to the views (unless if you want to store cross-view data, in this case you can assign it to the core - but it's recommended to add a name to this model.

So just move the model to the View by using this.getView().setModel() in the view's controller. (as you are trying to store the view name, it seems to be a view specific model).