[SAPUI5/OpenUI5]複数のプロパティをバインドする
SAPUI5/OpenUI5 関連の小ネタです。 複数のプロパティをデータバインドする方法についてです。
XMLView の場合、複数プロパティは以下のように割と簡単に実現できるのですが、JSView の場合はどうすればいいのでしょうか?
1
<text text="{Width} x {Depth} x {Height} {DimUnit}"></text>
答えはこちらです。
1
2
3
4
5
6
7
8
9
10
11
12
13
new sap.m.Text({
text: {
parts: [
{ path: "Width" },
{ path: "Depth" },
{ path: "Height" },
{ path: "DimUnit" },
],
formatter: function (width, depth, height, dimUnit) {
return width + " x " + depth + " x " + height + " " + dimUnit;
},
},
});
通常の formatter を使ったデータバインドはpathとformatterプロパティをセットすればいいのですが、複数プロパティの場合はpathをpartsの中に含めればできます。
最近、公式のサンプルを見る限り View は XMLView を使って書くべきみたいな流れになっていて、JSView のサンプルが減ってきていますね。。。
こちらに載っていた情報です。
This post is licensed under CC BY 4.0 by the author.