cancel
Showing results for 
Search instead for 
Did you mean: 

What's the defference between "new>PoItem" and "new>/PoItem" in data binding?

Former Member
0 Kudos

Hi experts,

    I'm confused about this question,What's the defference between "new>PoItem" and "new>/PoItem" in data binding?

    I create a model like this:

        var newModel = new sap.ui.model.json.JSONModel(sRootPath + "/model/mock.json");this.setModel(newModel, "new");

    When I do data binding,Sometimes "<Input type="Text" placeholder="{i18n>PoItem}" value="{new>/CompCode}" />" works,

    but sometimes "<Input type="Text" placeholder="{i18n>PoItem}" value="{new>CompCode}" />" works,why?

Best Regards,

felix zhao

Accepted Solutions (1)

Accepted Solutions (1)

MakotoS
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Felix,

This is something similar to the difference between "relative path" and "absolute path" in a file system.

If you are already in a specific position, you can use something like relative path in your model binding just like "{new>CompCode}"(otherwise, you need to specify with absolute path).

You can do the model-control binding in a parent level e.g. sap.m.Page or sap.m.App, View or others.

In this example, the model is bound in a page level and the root of JSON ( = "/" ) was bound by using bindElement method.

var input = new sap.m.Input({value: "{new>CompCode}" , width:"100px"}) ;

var page = new sap.m.Page({

  title: "page title",

  content: [

  input

  ]

});

var newModel = new sap.ui.model.json.JSONModel({"CompCode" : "test"});

page.setModel(newModel, "new");

page.bindElement("new>/");

This is very helpful when the JSON has a very deep structure, for example.  We only need to specify the path in parent level once if we use this.

And you may have seen this kind of technic is used in Master/Detail pattern as well.

I hope this helps.

Regards,

Makoto

Former Member
0 Kudos

thanks.

Best Regards,

felix zhao

Former Member
0 Kudos

Hi Makoto,

   in this case:

var oDeviceModel = new sap.ui.model.json.JSONModel({

  isTouch : sap.ui.Device.support.touch,

  isNoTouch : !sap.ui.Device.support.touch,

  isPhone : sap.ui.Device.system.phone,

  isNoPhone : !sap.ui.Device.system.phone,

  listMode : sap.ui.Device.system.phone ? "None" : "SingleSelectMaster",

  listItemType : sap.ui.Device.system.phone ? "Active" : "Inactive"

  });

  this.setModel(oDeviceModel, "device");

why doesn't it need "/"? "device>isPhone" is ok?

former_member182372
Active Contributor
0 Kudos

because if there is no explicit binding context it will assume root as a context, so isPhone == /isPhone

MakotoS
Product and Topic Expert
Product and Topic Expert
0 Kudos

I just have tested.

You need to use absolute path if you do not specify any explicit binding in advance.

If the "this" has bindElement method and you use it like below, then "device>isPhone" would also work I guess.

this.bindElement("device>/");

Without this.bindElement, it simply did now show the data in my testing.

Do you mean "device>isPhone" also worked in your case or not?

Former Member
0 Kudos

I didn't invoke this.bindElement("device>/"); and "device>isPhone" is ok.

So I guess,if ths json data has hierarchy(complex data structure), it needs "/" to access data,if ths json data is flat structure, it doesn't "/".

Am I right?

Former Member
0 Kudos

in my first case,"CompCode" is root element as well,but it needs "/".

typical case is i18n model,it doesn't need  "/".

why?

MakotoS
Product and Topic Expert
Product and Topic Expert
0 Kudos

This is the whole code i have tested.

can you try this in your environment? I this works, it might depend on UI5 version i think.

var input = new sap.m.Input({value: "{new>CompCode}" , width:"100px"}) ;

var page = new sap.m.Page({

  title: "page title",

  content: [

  input

  ]

});

var newModel = new sap.ui.model.json.JSONModel({"CompCode" : "test"});

input.setModel(newModel, "new");

//page.bindElement("new>/");

var app = new sap.m.App();

app.addPage(page);

app.placeAt("body");

MakotoS
Product and Topic Expert
Product and Topic Expert
0 Kudos

We were basically talking with the case of JSON model.

If you are using sap.ui.model.resource.ResourceModel, it will work differently.

That would be why it works in i18n model.

regards,

Makoto

Former Member
0 Kudos

Yes,your case works,Could you test like this:

replace var newModel = new sap.ui.model.json.JSONModel({"CompCode" : "test"});

with     var newModel = new sap.ui.model.json.JSONModel("/model/mock.json");


mock.json as

{ "CompCode" : "test" }


Former Member
0 Kudos

Your case doesn't work

  1.32.8 latest version

MakotoS
Product and Topic Expert
Product and Topic Expert
0 Kudos

What happens if you uncomment code below?

page.bindElement("new>/");

Former Member
0 Kudos

Hi Makoto,

   I'm sorry,it is my fault,"type="{device>/listItemType}""   deviceModel needs "/" too,

I have understood, thanks a lot.

as Maksim said:

"/" means absolute path. no "/" means relative path, relative to the current context binding of that element

MakotoS
Product and Topic Expert
Product and Topic Expert
0 Kudos

I tried the external JSON case but the behavior was all the same.

Former Member
0 Kudos

it needs "/" as well.

Former Member
0 Kudos

thanks a lot

MakotoS
Product and Topic Expert
Product and Topic Expert
0 Kudos

Yes, you are right.

I was tesing multiple things and it should be page.setModel().

input.setModel() was wrong.

As we want to specify the path with page level, both setModel() should bindElement() is in page level.

I think it will work if bindModel is in higher level than bindElement().

Now everything is working just I was thinking.

Former Member
0 Kudos

Yes,thank you again

Answers (1)

Answers (1)

former_member182372
Active Contributor
0 Kudos

"/" means absolute path. no "/" means relative path, relative to the current context binding of that element

Former Member
0 Kudos

thanks.

Best Regards,

felix zhao