on ‎2020 Sep 02 6:28 AM
<Select id="selApplication" forceSelection="false" change="handleChangeApplication" selectedKey="{/Applications/0/Application}" items="{path: '/Applications'}">
<core:Item key="{Application}" text="{Name}"/>
</Select>
I am using the above code snippet.
The JSONModel looks like this:
{
"Applications": [{
"Application": "GRN",
"Name": "Goods Receipt Note"
},
{
"Application": "NPO",
"Name": "Non-PO Invoice Approval"
}]
}
On initial load of application the Model remains same as above.
But when I change the selection in UI from GRN to NPO, on debugging the application in handleChangeApplication method, the Model changes to following:
{
"Applications": [{
"Application": "NPO",
"Name": "Goods Receipt Note"
},
{
"Application": "NPO",
"Name": "Non-PO Invoice Approval"
}]
}
As we can see, the Application value is automatically changed, this is causing issues.
Please help me in understanding where I am going wrong. Is this an issue with how I am binding the selectedKey?
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
I think this has to do with a reference problem in javascript objects, to avoid this I usually define a new property in the model.
<Select id="selApplication" forceSelection="false" change="handleChangeApplication" selectedKey="{/sSelectedKeyApplication}" items="{path: '/Applications'}">
<core:Item key="{Application}" text="{Name}"/>
</Select>//we define the key of the first element of the array
var aApplications = oModelJson.getProperty("/Applications");
var sKeyApplication = aApplications[0].Application;
oModelJson.setProperty("/sSelectedKeyApplication",sKeyApplication);I hope it helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ricardo,
It works fine. Thank you.
Also, went through the Chrome console to find that the default binding is 2 way. We can also use the below snippet to change it to OneWay.
oModel.setDefaultBindingMode(sap.ui.model.BindingMode.OneWay);
After the call, all future model assignments will be one way after this call.
| User | Count |
|---|---|
| 15 | |
| 9 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.