Lev83
Lev83

Reputation: 41

SAPUI5 - how to set value to input parameter in binding dynamically

In my XSOData service I have an entity based on calculation view with input parameters. I can to set these parameters as constants in my XML view, i.e.

<List items="{dicts>/AncParams(p_dict_name='GROUPS',p_rec_id=2)/Results}" >
        <StandardListItem
          title="{dicts>NAME}"
          />
    </List>

and it will work fine.

But how I can set parameters p_dict_name and p_rec_id dynamically? I tried to use expression bindings to get values for parameters from another model (something like this: <List items="{= ${dicts>/AncParams(p_dict_name='GROUPS',p_rec_id=${DictUIProps>/parentId})/Results} }" >) but with no luck. As I understand, expression bindings won't work. Is there any other way?

Upvotes: 0

Views: 3209

Answers (1)

Jorg
Jorg

Reputation: 7250

As far as I'm aware you can't do the aggregation binding dynamically through XML. At least not in the versions I have used and I have to admit I haven't re-checked in a while. The string never gets interpreted for inner bindings before it's applied to the model.

The way I do this is through the controller:

<List id="myList" />

and in your controller (onBeforeRendering or onPatternMatched or wherever your model and view are known to the controller):

this.getView().byId('myList').bindItems({
  model: 'dicts',
  path: `{/AncParams(p_dict_name='${p_dict_name}',p_rec_id=${p_rec_id})/Results}`,
  template: new sap.m.StandardListItem({
    title: '{dicts>NAME}'
  })
});

you can use the getModel('dicts').createKey function to generate the path name which is a little cleaner I suppose.

This is the way to apply dynamic filters as well, In case you ever build those.

Upvotes: 1

Related Questions