SAPUI5-How to bind data to sap.ui.layout.form?

2019-06-06 01:25发布

How to bind json data to form.Below is my form and data to be binded. Please help me with this. Example i want to bind 111 object values to the form

Data:
{"customerdetailsjson": {
        "111": [
            {
                "name": "Bhuvaneswari Krishnan",
               "phone-number":"8050231233"
            }
        ],
        "112": [
            {
                 "name":"Chetan Sandeep Renu",
       "phone-number":"9840321321"
            }
        ]
    }}

Form:
var oLayout1 = new sap.ui.layout.form.ResponsiveGridLayout();
customerDetailsForm = new sap.ui.layout.form.Form("F1", {
layout: oLayout1,
formContainers: [new sap.ui.layout.form.FormContainer("F1C2", {
    title: new sap.ui.core.Title({
        text: "Address Information",
        tooltip: "Address data"
    }),
    formElements: [new sap.ui.layout.form.FormElement({
        label: "Street / Number",
        fields: [new sap.m.Input({
            type: sap.m.InputType.Text,
            value: "{name}",
            layoutData: new sap.ui.core.VariantLayoutData({
                multipleLayoutData: [new sap.ui.layout.ResponsiveFlowLayoutData({
                    weight: 5
                }), new sap.ui.layout.form.GridElementData({
                    hCells: "5"
                })]
            })
        })]
    }), new sap.ui.layout.form.FormElement({
        label: "Street / Number",
        fields: [new sap.m.Input({
            type: sap.m.InputType.Text,
            value: "{phone-number}",
            layoutData: new sap.ui.core.VariantLayoutData({
                multipleLayoutData: [new sap.ui.layout.ResponsiveFlowLayoutData({
                    weight: 5
                }), new sap.ui.layout.form.GridElementData({
                    hCells: "5"
                })]
            })
        })]
    })]
})]
})]

标签: sapui5
1条回答
叼着烟拽天下
2楼-- · 2019-06-06 01:37

First of all you need a model:

var myModel = new sap.ui.model.json.JSONModel(myJsonData);

Then you assign it to your control:

customerDetailsForm.setModel(myModel);

Now you can start binding values from your model to the control (and also sub-controls) by using an absolute path from the root node of your model:

    ...
    new sap.ui.layout.form.FormElement({
            label: "Street / Number",
            fields: [new sap.m.Input({
                type: sap.m.InputType.Text,
                value: "{/customerdetailsjson/111/0/name}",
                layoutData: new sap.ui.core.VariantLayoutData({
                    multipleLayoutData: [new sap.ui.layout.ResponsiveFlowLayoutData({
                        weight: 5
                    }), new sap.ui.layout.form.GridElementData({
                        hCells: "5"
                    })]
                })
            })]
   ...

GL Chris

查看更多
登录 后发表回答