SAPUI5如何将数据绑定到sap.ui.layout.form?
如何将json数据绑定到表单。下面是我的表单和要绑定的数据。 请帮我做这个。 示例我想将111个对象值绑定到表单SAPUI5如何将数据绑定到sap.ui.layout.form?,sapui5,Sapui5,如何将json数据绑定到表单。下面是我的表单和要绑定的数据。 请帮我做这个。 示例我想将111个对象值绑定到表单 Data: {"customerdetailsjson": { "111": [ { "name": "Bhuvaneswari Krishnan", "phone-number":"8050231233" } ], "112"
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);
然后将其分配给控件:
customerDetailsForm.setModel(myModel);
现在,通过使用模型根节点的绝对路径,可以开始将值从模型绑定到控件以及子控件:
...
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"
})]
})
})]
...
德国劳埃德船级社
克里斯首先,你需要一个模型:
var myModel = new sap.ui.model.json.JSONModel(myJsonData);
然后将其分配给控件:
customerDetailsForm.setModel(myModel);
现在,通过使用模型根节点的绝对路径,可以开始将值从模型绑定到控件以及子控件:
...
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"
})]
})
})]
...
德国劳埃德船级社
ChrisHi,谢谢你的回复。这个值有一个疑问:{/customerdetailsjson/111/0/name}我们可以使用bindContext或其他东西使这个customerdetailsjson/111成为动态的吗?请帮助我1。您可以去掉1102中不必要的数组。如果您的父控件允许聚合绑定,例如sap.m.List上的项,您可以绑定数据中的数组,例如{/customerdetailsjson/111},并在重复控件内使用相对无前导/绑定,例如sap.m.DisplayListItem,如此{name}@Papu顺便说一句:如果有帮助,您可以将我的答案标记为正确。谢谢,谢谢你的回复。这个值有一个疑问:{/customerdetailsjson/111/0/name}我们可以使用bindContext或其他东西将这个customerdetailsjson/111设置为动态的吗?请帮助我1。您可以去掉1102中不必要的数组。如果您的父控件允许聚合绑定,例如sap.m.List上的项,您可以绑定数据中的数组,例如{/customerdetailsjson/111},并在重复控件内使用相对无前导/绑定,例如sap.m.DisplayListItem,如此{name}@Papu顺便说一句:如果有帮助,您可以将我的答案标记为正确。谢谢