如何在包含控件的 sap.uxap.BlockBase 上设置 `fieldGroupIds`?
How to set `fieldGroupIds` on sap.uxap.BlockBase containing controls?
假设我有一个像这样的 SAPUI5 应用程序 sample application。
正如在此应用程序的代码中所见,视图以某种方式分成几个块并附加到主视图,如下所示:
<ObjectPageSubSection title="Payment information">
<blocks>
<personal:PersonalBlockPart1 id="part1"/>
</blocks>
<moreBlocks>
<personal:PersonalBlockPart2 id="part2"/>
</moreBlocks>
</ObjectPageSubSection>
并且 PersonalBlockPart1
被分成两个文件,如下所示:
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:forms="sap.ui.layout.form" xmlns="sap.m">
<forms:SimpleForm editable="false" layout="ColumnLayout">
<core:Title text="Main Payment Method"/>
<Label text="Bank Transfer"/>
<Text text="Sparkasse Heimfeld, Germany"/>
</forms:SimpleForm>
</mvc:View>
sap.ui.define(['sap/uxap/BlockBase'], function (BlockBase) {
"use strict";
var BlockJobInfoPart1 = BlockBase.extend("sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1", {
metadata: {
views: {
Collapsed: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
},
Expanded: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
}
}
}
});
return BlockJobInfoPart1;
});
如果我想设置 fieldGroupIds
一个直接的方法是在代码的 xml
片段中进行设置!例如:
<Text text="Sparkasse Heimfeld, Germany" fieldGroupIds="XYZ1"/>
我的问题是如何在父视图中执行此操作,如下所示:
<blocks>
<personal:PersonalBlockPart1 id="part1" fieldGroupIds="XYZ1"/>
</blocks>
<moreBlocks>
<personal:PersonalBlockPart2 id="part2" fieldGroupIds="XYZ2"/>
</moreBlocks>
我试过了,显然不适用于儿童控件。但是,我认为可能有一个解决方案可以从主 XML 视图读取此 属性 并将其应用到所有封闭控件的 JS
文件中,如下所示:
sap.ui.define(['sap/uxap/BlockBase'], function (BlockBase) {
"use strict";
var BlockJobInfoPart1 = BlockBase.extend("sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1", {
metadata: {
views: {
Collapsed: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
},
Expanded: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
}
}
},
onViewInit: function(){
// pseudocode
var sFieldGroupIds = this.getFieldGroupIds();
var aControls = this.getAllFeidls();
iterate over aControls and set the sFieldGroupId
}
});
return BlockJobInfoPart1;
});
我必须使用 onBeforeRendering
功能:
sap.ui.define(['sap/uxap/BlockBase'], function (BlockBase) {
"use strict";
var setFieldGroupIdsRecursively = function (oControl, sFieldGroupIds) {
var aPossibleAggregations = ["items", "content", "form", "formContainers", "formElements", "fields", "cells"];
if (oControl instanceof sap.m.InputBase || oControl instanceof sap.ui.comp.smartfield.SmartField) {
oControl.setFieldGroupIds(sFieldGroupIds);
return;
}
for (var i = 0; i < aPossibleAggregations.length; i += 1) {
var aControlAggregation = oControl.getAggregation(aPossibleAggregations[i]);
if (aControlAggregation) {
// generally, aggregations are of type Array
if (aControlAggregation instanceof Array) {
for (var j = 0; j < aControlAggregation.length; j += 1) {
setFieldGroupIdsRecursively(aControlAggregation[j], sFieldGroupIds);
}
}
else { // ...however, with sap.ui.layout.form.Form, it is a single object *sigh*
setFieldGroupIdsRecursively(aControlAggregation, sFieldGroupIds);
}
}
}
};
var BlockJobInfoPart1 = BlockBase.extend("sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1", {
metadata: {
views: {
Collapsed: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
},
Expanded: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
}
}
},
onBeforeRendering: function () {
var aFieldGroupIds = this.getFieldGroupIds(),
sFieldGroupIds = "";
if (aFieldGroupIds.length > 0) {
sFieldGroupIds = aFieldGroupIds.join();
var oView = sap.ui.getCore().byId(this.getSelectedView());
if (oView) {
var aContent = oView.getContent();
for (var j = 0; j < aContent.length; j++) {
setFieldGroupIdsRecursively(aContent[j], sFieldGroupIds);
}
}
}
}
});
return BlockJobInfoPart1;
});
假设我有一个像这样的 SAPUI5 应用程序 sample application。
正如在此应用程序的代码中所见,视图以某种方式分成几个块并附加到主视图,如下所示:
<ObjectPageSubSection title="Payment information">
<blocks>
<personal:PersonalBlockPart1 id="part1"/>
</blocks>
<moreBlocks>
<personal:PersonalBlockPart2 id="part2"/>
</moreBlocks>
</ObjectPageSubSection>
并且 PersonalBlockPart1
被分成两个文件,如下所示:
<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns:core="sap.ui.core" xmlns:forms="sap.ui.layout.form" xmlns="sap.m">
<forms:SimpleForm editable="false" layout="ColumnLayout">
<core:Title text="Main Payment Method"/>
<Label text="Bank Transfer"/>
<Text text="Sparkasse Heimfeld, Germany"/>
</forms:SimpleForm>
</mvc:View>
sap.ui.define(['sap/uxap/BlockBase'], function (BlockBase) {
"use strict";
var BlockJobInfoPart1 = BlockBase.extend("sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1", {
metadata: {
views: {
Collapsed: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
},
Expanded: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
}
}
}
});
return BlockJobInfoPart1;
});
如果我想设置 fieldGroupIds
一个直接的方法是在代码的 xml
片段中进行设置!例如:
<Text text="Sparkasse Heimfeld, Germany" fieldGroupIds="XYZ1"/>
我的问题是如何在父视图中执行此操作,如下所示:
<blocks>
<personal:PersonalBlockPart1 id="part1" fieldGroupIds="XYZ1"/>
</blocks>
<moreBlocks>
<personal:PersonalBlockPart2 id="part2" fieldGroupIds="XYZ2"/>
</moreBlocks>
我试过了,显然不适用于儿童控件。但是,我认为可能有一个解决方案可以从主 XML 视图读取此 属性 并将其应用到所有封闭控件的 JS
文件中,如下所示:
sap.ui.define(['sap/uxap/BlockBase'], function (BlockBase) {
"use strict";
var BlockJobInfoPart1 = BlockBase.extend("sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1", {
metadata: {
views: {
Collapsed: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
},
Expanded: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
}
}
},
onViewInit: function(){
// pseudocode
var sFieldGroupIds = this.getFieldGroupIds();
var aControls = this.getAllFeidls();
iterate over aControls and set the sFieldGroupId
}
});
return BlockJobInfoPart1;
});
我必须使用 onBeforeRendering
功能:
sap.ui.define(['sap/uxap/BlockBase'], function (BlockBase) {
"use strict";
var setFieldGroupIdsRecursively = function (oControl, sFieldGroupIds) {
var aPossibleAggregations = ["items", "content", "form", "formContainers", "formElements", "fields", "cells"];
if (oControl instanceof sap.m.InputBase || oControl instanceof sap.ui.comp.smartfield.SmartField) {
oControl.setFieldGroupIds(sFieldGroupIds);
return;
}
for (var i = 0; i < aPossibleAggregations.length; i += 1) {
var aControlAggregation = oControl.getAggregation(aPossibleAggregations[i]);
if (aControlAggregation) {
// generally, aggregations are of type Array
if (aControlAggregation instanceof Array) {
for (var j = 0; j < aControlAggregation.length; j += 1) {
setFieldGroupIdsRecursively(aControlAggregation[j], sFieldGroupIds);
}
}
else { // ...however, with sap.ui.layout.form.Form, it is a single object *sigh*
setFieldGroupIdsRecursively(aControlAggregation, sFieldGroupIds);
}
}
}
};
var BlockJobInfoPart1 = BlockBase.extend("sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1", {
metadata: {
views: {
Collapsed: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
},
Expanded: {
viewName: "sap.uxap.sample.SharedBlocks.employment.BlockJobInfoPart1",
type: "XML"
}
}
},
onBeforeRendering: function () {
var aFieldGroupIds = this.getFieldGroupIds(),
sFieldGroupIds = "";
if (aFieldGroupIds.length > 0) {
sFieldGroupIds = aFieldGroupIds.join();
var oView = sap.ui.getCore().byId(this.getSelectedView());
if (oView) {
var aContent = oView.getContent();
for (var j = 0; j < aContent.length; j++) {
setFieldGroupIdsRecursively(aContent[j], sFieldGroupIds);
}
}
}
}
});
return BlockJobInfoPart1;
});