SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.96k stars 1.24k forks source link

relative path in JsonModel.getProperty() #2505

Open wernerdaehn opened 5 years ago

wernerdaehn commented 5 years ago

Imagine a code like this

onPress : function(oEvent) {
    var path = oEvent.getSource().getBindingContext().getPath();
    var oModel = this.getView().getModel();
    var obj = oModel.getProperty(path);
}

You get a path, hence you know you are in /database/0/connection/4/name but very likely you will need elements from parents as well. Only solution is to split the string and construct the path again, e.g. oModel.getProperty(/database/0/connection/4/host); or oModel.getProperty(/database/0/databasetype);

With relative path support that would be easier:

oModel.getProperty(path + "/../host");

Or even better: A set of methods to navigate programatically, e.g.

oModel.getNode(path).getParentNode().getProperty();
Shtilianova commented 5 years ago

Hello @wernerdaehn , Thank you for share your enhancement proposal. I've created an internal incident 1980265594. The status of the issue will be updated here in GitHub. Regards, Diana

Thodd commented 5 years ago

As discussed in issue/2504:

@wernerdaehn original example for relative binding paths in composite bindings:

Imagine the situation where you use a JsonModel as the source of your e.g. tree table with databasevendor -> databaseversion -> connectioninfo.

If somebody does something on the connectioninfo level, it is very likely he will need the parent version as well, e.g. a formatter creating the link for the connection info screen.

If you could specify things like "{ parts: [ 'connectionname', '../databaseversion', '../../databasevendor'] }"

uhlmannm commented 2 years ago

Hi @wernerdaehn ,

I have logged your requirement as CPOUI5MODELS-900 internally consisting of two parts:

Acceptance Criteria

  • It is possible to specify paths containing ../ in sap.ui.model.json.JSONModel#getProperty.
    • It is possible to specify relative paths with ../ in property bindings when a JSONModel is used.

Unfortunately, I cannot provide any forecast as to when this could get addressed.

Best regards Mathias.