Skip to Content
0

SAPUI5 Binding Context for aggregation

Nov 13, 2017 at 01:25 PM

44

avatar image

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?

10 |10000 characters needed characters left characters exceeded

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

0
* Please Login or Register to Answer, Follow or Comment.

0 Answers