如何在 sap.m.TileContent 的内容中添加多个控件? [英] How to add multiple control inside the content of sap.m.TileContent?
问题描述
下面的代码适用于 sap.m.TileContent 中的单个控件
Below code is working fine for single control inside sap.m.TileContent
var oTile = new sap.m.GenericTile({
header: oData.results[i].Name,
subheader: oData.results[i].ModuleName,
size: "Auto",
frameType: "OneByOne",
press: [that.handleTilePress, that],
tileContent: [new sap.m.TileContent({
size: "Auto",
footer: oData.results[i].Num.toLocaleString() + " views",
content: [new sap.m.NumericContent({
size: "Auto",
nullifyValue: false,
icon: "sap-icon://"+oData.results[i].tileIcon
})]
})]
});
但是当我尝试向 sap.m.TileContent 添加一个控件时,假设 sap.m.TileContent 中的 sap.m.Label 如下所示,
But when I tried to add one more control to sap.m.TileContent, let's say sap.m.Label inside sap.m.TileContent as below,
var oTile = new sap.m.GenericTile({
header: oData.results[i].Name,
subheader: oData.results[i].ModuleName,
size: "Auto",
frameType: "OneByOne",
press: [that.handleTilePress, that],
tileContent: [new sap.m.TileContent({
size: "Auto",
footer: oData.results[i].Num.toLocaleString() + " views",
content: [new sap.m.NumericContent({
size: "Auto",
nullifyValue: false,
icon: "sap-icon://"+oData.results[i].tileIcon
}),
new sap.m.Label({text:"dummyText"})]
})]
})
它给了我一个错误,如试图将一组控件添加到单个聚合"(内容中的单个控件工作正常,即标签或数字内容)
It's giving me an error as "Tried to add an array of controls to a single aggregation" (Single control inside the content is working fine i.e. either the label or the numeric content)
我正在寻找除内容"之外的任何其他替代方法来添加多个控件,或者在不开发自定义控件的情况下以任何方式在内容中添加多个控件.如何解决这个问题?
I am looking for any other alternative except 'content' to add multiple controls or any way to add multiple control inside content without developing the custom control. How to solve this?
PS:我想将 sap.m.RatingIndicator 添加到磁贴,以便我可以实现最喜欢的功能.
PS: I want to add sap.m.RatingIndicator to the tile so that I can implement the favourite functionality.
推荐答案
发生这种情况是因为 sap.m.TileContent 聚合 的基数为 0..1,其中 0 是最小基数,1 是最大基数.这意味着在 content 属性中只能有一个项目.
This is happening because content in sap.m.TileContent aggregations has the cardinality of 0..1 where 0 is the minimum cardinality, and 1 is the maximum cardinality. This means you can only have a single item inside the content property.
您应该遵循 Fiori 评级指标设计指南仅在表单、表格或对话框中使用此元素.话虽如此,如果您像这样将其插入 sap.m.TileContent 中,它仍然可以工作:
Following the Fiori Design Guidelines for Rating Indicator you should only use this element in forms, tables or in a dialog box. With that said, it will still work if you insert it into sap.m.TileContent like this:
<GenericTile header="Cumulative Totals" subheader="Expenses">
<TileContent unit="Unit" footer="Footer Text">
<content>
<RatingIndicator id="RI_default" maxValue="5" value="4" tooltip="Rating Tooltip"/>
</content><!-- sap.ui.core.Control -->
</TileContent>
</GenericTile>
如果您想在磁贴中添加其他文本,我建议您使用 sap.m.TileContent 中的页脚和/或单位属性,就像我上面的示例一样.
If you want to add other text in the tile I would suggest you use the footer and/or unit properties in sap.m.TileContent just like in my example above.
您可以通过插入 sap.m.VBox 元素在您的 sap.m.TileContent 中并在那里插入多个元素,尽管我真的建议您不要这样做!
You can workaround the cardinality of the sap.m.TileContent aggregations by inserting a sap.m.VBox element inside your sap.m.TileContent and insert multiple elements there although I really would advise you not to do it!
示例:
<GenericTile header="Cumulative Totals" subheader="Expenses">
<TileContent unit="Unit" footer="Footer Text">
<content>
<VBox>
<RatingIndicator id="RI_default" maxValue="5" value="4"/>
<Label text="Dummy"/>
</VBox>
</content>
</TileContent>
</GenericTile>
希望有帮助!
这篇关于如何在 sap.m.TileContent 的内容中添加多个控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!