SAPUI5-如何将数据绑定到 sap.ui.layout.form? [英] SAPUI5-How to bind data to sap.ui.layout.form?
本文介绍了SAPUI5-如何将数据绑定到 sap.ui.layout.form?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将json数据绑定到form上.下面是我要绑定的form和数据.请帮我解决一下这个.示例我想将 111 个对象值绑定到表单
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"
})]
})
})]
})]
})]
})]
推荐答案
首先你需要一个模型:
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克里斯
这篇关于SAPUI5-如何将数据绑定到 sap.ui.layout.form?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文