cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Binding Context for aggregation

former_member239819
Participant
0 Kudos

I have a "questions" object which contains an "answers" array...

<code>var oModel = new JSONModel({
            questions: [{
                order: 1,
                title: "",
                answers: [{
                    sequence: 1,
                    label: "Yes",
                }, {
                    sequence: 3,
                    label: "N/A",
                }]
            }]
        });

And the context set as follows...

<code>        this.getView().setModel(oModel, "viewmodel");
        var oContext = oModel.createBindingContext("/questions/0/");
        this.getView().setBindingContext(oContext, "viewmodel");

In my view, I can bind questions fine...

<code><Input value="{viewmodel>title}"/>

However, updating the answers binding updates ALL the answer arrays in EVERY questions context!, e.g. below i'm binding to my current context (questions/0/) but updating the label will update the answers for all questions....

<code><f:Form id="formCustomRadio" editable="true" visible="true" formContainers="{viewmodel>answers}">
                    <f:layout>
                        <f:ResponsiveGridLayout/>
                    </f:layout>
                    <f:formContainers>
                        <f:FormContainer title="Answer {viewmodel>sequence}">
                            <f:formElements>
                                <f:FormElement label=" {i18n>radioLabel}">
                                    <f:fields>
                                        <Input value="{viewmodel>label}"/>
                                    </f:fields>

Any ideas?

former_member239819
Participant
0 Kudos

Any advice at all?

The binding of viewmodel>label is correctly set to questions/(context)/answers/(context).

e.g questions/1/answers/0/ for the first label of the 2nd questions array/

The issue is both questions/0 and questions/1 are being updated with the change to questions/1/answers/0/label.

In fact ALL corresponding answers for ALL questions are being updated if just a single change is made to an element of answers

Accepted Solutions (0)

Answers (0)