Skip to Content

SAPUI5 Binding Context for aggregation

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:FormContainer title="Answer {viewmodel>sequence}">
                                <f:FormElement label=" {i18n>radioLabel}">
                                        <Input value="{viewmodel>label}"/>

Any ideas?

Add comment
10|10000 characters needed 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

  • Get RSS Feed

0 Answers