single template control์ ํ๋ ์ฝ๋ฉํ๋ ๋์ factory function์ ์ฌ์ฉํ์ฌ runtime์ ์์ ๋ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ค๋ฅธ control์ ์์ฑํ๋ค.
์ด ์ ๊ทผ ๋ฐฉ์์ ํจ์ฌ ๋ ์ ์ฐํ๋ฉฐ ๋ณต์กํ๊ฑฐ๋ ์ด์ง์ ์ธ ๋ฐ์ดํฐ๋ฅผ ํ์ํ ์ ์๋ค.
<Panel headerText="{i18n>panel4HeaderText}" class="sapUiResponsiveMargin" width="auto">
<List id="ProductList" headerText="{i18n>productListTitle}" items="{
path: 'products>/Products',
factory: '.productListFactory'}">
<dependents>
<core:Fragment fragmentName="databinding.view.ProductSimple" type="XML"/>
<core:Fragment fragmentName="databinding.view.ProductExtended" type="XML"/>
</dependents>
</List>
</Panel>
์ด์ ์ product list๋ฅผ ๊ฐ์ง๊ณ ์๋ List XML element๋ ์ด์ fragment๋ก ์ถ์๋์ง๋ง ๊ทธ๋ ์ง ์์ผ๋ฉด list๋ ๋น์ด ์๋ค. ์ด list๋ฅผ ์ฑ์ธ ์ ์๋ factory function์ด ์์ผ๋ฉด ์ด list๋ ํญ์ ๋น์ด ์๋ค.
'sap/m/ObjectAttribute'], function (..., ObjectAttribute) {
"use strict";
...
ProductListFactory: function(sId, oContext) {
let oUIControl;
// clone์ ์์กดํ๋ data๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ฒฐ์
if (oContext.getProperty('UnitsInStock') === 0 && oContext.getProperty('Discontinued')) {
// The item is discontinued, so use a StandardListItem
oUIControl = this.byId('productSimple').clone(sId);
} else {
// The item is available, so we will create an ObjectListItem
oUIControl = this.byId('productExtended').clone(sId);
// The item is temporarily out of stock, so we will add a status
if ( oContext.getProperty('UnitsInStock') < 1 ) {
oUIControl.addAttribute(new ObjectAttribute({
text : {
path: 'i18n>outOfStock'
}
}));
}
}
return oUIControl;
}
}
factory function์ ์ด์ ๋จ๊ณ์์ ์ ์ํ XML template๊ณผ ์ ์ฌํ ๊ด๋ จ binding context์ ๋ํ control์ ๋ฐํํ๋ค.
์ด factory function์ด ๋ฐํํ๋ control type์ sap.m.List ๊ฐ์ฒด์ ํญ๋ชฉ aggregation์ ์ ํฉํด์ผ ํ๋ค.
์ด ๊ฒฝ์ฐ ์์ฑํ ํญ๋ชฉ์ context์ ์ ์ฅ๋ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก StandardListItem ๋๋ ObjectListItem์ ๋ฐํํ๋ค.
ํ์ฌ ์ฌ๊ณ ์์ค๊ณผ ์ ํ์ ๋จ์ข
์ฌ๋ถ๋ฅผ ํ์ธํ์ฌ ์ด๋ค ์ข
๋ฅ์ ์ ์ด์ฅ์น๋ฅผ ๋ฐํํ ์ง ๊ฒฐ์ ํ๋ค. ๋ ์ต์
๋ชจ๋ XML์ ๋๊ณ
๋ก๋ํ์ฌ ๋ทฐ ๋ก์ง์ ์ ์ธ์ ์ผ๋ก ์ ์ํ๊ณ ํ์ฌ ์ปจํธ๋กค๋ฌ์ ํ ๋นํ ์ ์๋ค. ์ฌ๊ณ ๋ ๋ฒจ์ด 0์ด๊ณ ๋จ์ข
๋ ๊ฒฝ์ฐ ProductSimple(sap.m.StandardListItem),
๊ทธ๋ ์ง ์์ ๊ฒฝ์ฐ ProductExtended(sap.m.ObjectListItem)๋ฅผ ์ฌ์ฉํ๋ค.
XML ํ๋๊ทธ๋จผํธ๋ ๊ฐ ๊ฒฝ์ฐ์ ํ ๋ฒ๋ง ๋ก๋ํ๋ฉด ๋๋ฏ๋ก ์ปจํธ๋กค๋ฌ์ helper varaible์ ์ ์ฅํ๊ณ ํ ๋ฒ๋ง ๋ก๋ํ์ฌ
Singleton์ ๋ง๋ ๋ค. list์ ๊ฐ ํญ๋ชฉ์ ๋ํด ์ปจํธ๋กค๋ฌ์ ์ ์ฅ๋ ํด๋น control์ ๋ณต์ ํ๋ค. ์ด ๋ฉ์๋๋ list ํญ๋ชฉ์ context์ bindingํ ์ ์๋ control์ ์ ๋ณต์ฌ๋ณธ์ ๋ง๋ ๋ค.
์ฐธ๊ณ : facotry function์์๋ ์์ฑํ control์ life cycle์ ๋ํ ์ฑ
์์ด ์๋ค.
๋จ์ข
๋ ์ ํ์ ์์ง๋ง ์ฌ๊ณ ๊ฐ 0์ธ ๊ฒฝ์ฐ ์ผ์์ ์ผ๋ก ํ์ ๋๋ค. ์ด ๊ฒฝ์ฐ Javascript๋ฅผ ์ฌ์ฉํ์ฌ control์ ์ฌ๊ณ ์์ ๋ฉ์์ง๋ฅผ ์ถ๊ฐํ๋ ๋จ์ผ ObjectAttribute๋ฅผ ์ถ๊ฐํ๋ค.
XML view๋ fragment์์ ์ ์ธ์ ์ ์์ ์ ์ฌํ๊ฒ data binding syntax์ ์ฌ์ฉํ์ฌ ์์ฑ์ ๋ฐ์ธ๋ฉํ ์ ์๋ค.
์ด ๊ฒฝ์ฐ ํ
์คํธ๋ฅผ ๋ฆฌ์์ค ๋ฒ๋ค์ ์์ฑ์ ๋ฐ์ธ๋ฉํ๋ค.
์์ฑ์ ๋ชฉ๋ก ํญ๋ชฉ์ ํ์ ํญ๋ชฉ์ด๋ฏ๋ก ํ ๋น๋ ๋ชจ๋ ๋ชจ๋ธ๊ณผ ํ์ฌ ๋ฐ์ธ๋ฉ ์ปจํ
์คํธ์ ์ก์ธ์คํ ์ ์๋ค.
StandardListItem
์ ์ ์ํ๋ค.<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<StandardListItem
id="productSimple"
icon="sap-icon://warning"
title="{products>ProductName} ({products>QuantityPerUnit})"
info="{i18n>Discontinued}"
type="Active"
infoState="Error"
press=".onItemSelected">
</StandardListItem>
</core:FragmentDefinition>
ObjectListItem
์ ๋ง๋ ๋ค.<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<ObjectListItem
id="productExtended"
title="{products>ProductName} ({products>QuantityPerUnit})"
number="{
parts: [
{path: 'products>UnitPrice'},
{path: '/currencyCode'}
],
type: 'sap.ui.model.type.Currency',
formatOptions : {
showMeasure : false
}
}"
type="Active"
numberUnit="{/currencyCode}"
press=".onItemSelected">
</ObjectListItem>
</core:FragmentDefinition>
# Product Details
outOfStock=Out of Stock
sapui5์์ ์ ๊ณตํ๋ databinding์๋ํด ํฐ ํ์ ๊ฐ๋ ๋ง ๋ค๋ฃจ์์ต๋๋ค. ์ถํ databinding์ ๋ ๋ฅํ๊ฒ ์์๋ณด๊ณ ๋ง์ ์์ ํ์ผ์ ๋ง๋ค์ด ๊ณต์ ํ๊ฒ ์ต๋๋ค. databinding tutorial์์ ๋ด์ฉ์ด ์๋ชป๋๊ฑฐ๋ ์ค๋ช ์ด ๋ถ์กฑํ ๋ถ๋ถ์ ๋๊ธ์ ๋ฌ๊ฑฐ๋ ์ด๋ฉ์ผ์ ๋ณด๋ด์ฃผ๊ธธ ๋ฐ๋๋๋ค~~ ์ต๋ํ ๋นจ๋ฆฌ ๋ณด์ํด์ ์์ ํ๊ฒ ์ต๋๋ค. ๐๐๐