on 02-02-2016 12:59 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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?
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");
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.
"/" means absolute path. no "/" means relative path, relative to the current context binding of that element
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.