2
votes

I have a view in my sapui5 app, where on a button press I want to pass some data to the controller, to the function invoked on the press event. Below is the code snippet :

 <HBox justifyContent="SpaceAround" alignItems="Center" >
    <Input type="Tel" pattern="[0-9]*" inputmode="numeric"
         value="{path:'cart>Quantity/value',
                type: 'sap.ui.model.type.Integer'}"
         class="qtyInput" editable="{cart>Quantity/isEditable}"/>
    <core:Icon src="sap-icon://delete" press="deleteItem" visible="{cart>isDeletable}"/>
 </HBox>

Here, I need to pass "{cart>lineNumber}" and ”{cart>itemKey}" to the function “deleteItem” which is there in the controller. Please suggest.

2

2 Answers

2
votes

You can try using sapui5 CustomData to pass your custom data on a event. For that, you need to add below namespace in your view:

xmlns:app="http://schemas.sap.com/sapui5/extension/sap.ui.core.CustomData/1"

and add app:propertyName=“value” inside the Icon element.

Please take a look at below example, I updated your code with the changes required:

<core:Icon src="sap-icon://delete" press="deleteItem" visible="{cart>isDeletable}" app:lineNumber="{cart>lineNumber}" app:itemKey="{cart>itemKey}"/>

Thanks.

0
votes

Another way to resolve this problem is, if you are getting the data from the same model on which the list is being iterated, you may get the index number of the list item and then read the specific record from the model itself using the index number. Let me know if you need a code example for this.