on 01-09-2017 8:41 PM
I build a universal model for all dropdown values:
var oCaseListDropdownModel = new sap.ui.model.json.JSONModel();
sap.ui.getCore().setModel(oCaseListDropdownModel, "CaseListDropdownModel");
Then later, within a service call, I put the values in the model:
oCaseListDropdownModel.setData(data.d);
oCaseListDropdownModel.refresh(true);
I have a view that has these controls:
<f:FormElement label="Status" id="__caseInfoStatusForm">
<f:fields>
<Input id="__caseInfoStatusDesc" value="{/Status}" editable="false"/>
</f:fields>
</f:FormElement>
<f:FormElement label="Site" id="caseCreateelement11">
<ActionSelect id="caseCreateStationId" selectedKey="{/StationId}" items="{path: '/results', filters: [ { path: 'Field', operator: 'EQ', value1: 'Site' } ] }" enabled="true">
<items>
<sap.ui.core:ListItem text="{Value}" key="{Key}" />
</items>
</ActionSelect>
</f:FormElement>
In the controller for that view, I build the model like this:
oCaseCreateModel.setData(
{
"Status" : "E0001",
"StationId" : ""
}
);
oCaseCreateModel.refresh(true);
this.getView().setModel(oCaseCreateModel);
Then, for the dropdown, I do this:
oCaseListDropdownModel = sap.ui.getCore().getModel("CaseListDropdownModel");
var thisCaseCreate = this;
thisCaseCreate.getView().byId("caseCreateStationId").setModel(oCaseListDropdownModel);
Later, when it is time to call the POST service, I get the model from the view:
oCaseCreateViewModel = thisCaseCreate.getView().getModel("undefined");
But when I do that, it does not bring in the key value that the user selected, and instead brings in the key value that was set initially, when the model was populated.
I have found that, for each dropdown, I have to do this:
oCaseCreateViewModel.setProperty("/StationId", thisCaseCreate.getView().byId("caseCreateStationId").getSelectedKey());
Why does the selectedKey for /StationId not get updated in the model automatically?
this.getView().setModel(oCaseCreateModel);
thisCaseCreate.getView().byId("caseCreateStationId").setModel(oCaseListDropdownModel);
you set unnamed model twice. so the second one will be in charge.
so the selected key goes to oCaseListDropdownModel, not the oCaseCreateViewModel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oCaseCreateViewModel = thisCaseCreate.getView().getModel("undefined");
"undefined"??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.