/scripts/ahub.form.attachments.js
0

How to bind selectkeys which have items from a different model?

Jan 09, 2017 at 08:41 PM

41

avatar image

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?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Jun Wu Jan 10, 2017 at 05:57 AM
0
  oCaseCreateViewModel = thisCaseCreate.getView().getModel("undefined");

"undefined"??
Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Jan 10, 2017 at 06:03 AM
0
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
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Thanks for responding.

I wonder if there is a better way to go about doing this.

0

do what?.............

0
Skip to Content