์ฌ์ฉ์์๊ฒ 'ํ๊ธธ๋'์ด๋ผ๋ ์ฌ๋์ ์ฐ๋ฝํ ์ ์๋ ๋ฐฉ๋ฒ์ ์ ๊ณตํ๊ณ ์ ํ๋ค. ์ฐ๋ฆฌ๋ ํ๊ธธ๋์๊ฒ ์ด๋ฉ์ผ์ ๋ณด๋ด๋ ๋งํฌ๋ฅผ
์ถ๊ฐํ ๊ฒ์ด๋ค. ์ด๋ฅผ ์ํด Model์ ๋ฐ์ดํฐ๋ฅผ sap.m๊ณผ ์ผ์นํ๋๋ก ๋ณํํ๋ค. URLHelper.Email API๋ฅผ ์ ๊ทํํ๋ค,
์ฌ์ฉ์๊ฐ ์ด๋ฆ์ ๋ณ๊ฒฝํ๋ ์ฆ์ ์ ์ ๋ฉ์ผ๋ ๋ณ๊ฒฝ๋๋ค. ์ด๋ฅผ ์ํด์ custom formatter function์ด ํ์ํ๋ค.
sap.ui.defind([
'sap/ui/core/mvc/Controller',
'sap/m/library'
]), function (Controller, mobileLibrary) {
'use strict';
return Controller.extend('...', {
formatMail: function(sFirstName, sLastName) {
const oBundle = this.getView().getModel('i18n').getResourceBundle();
return mobileLibrary.URLHelper.normalizeEmail(
sFirstName + '.' + sLastName + '@example.com',
oBundle.getText('mailSubject', [sFirstName]),
oBundle.getText('mailBody'));
}
})
}
custom formatter์์๋ ํ์ฌ Model์ ์๋ ์ฑ๊ณผ ์ด๋ฆ์ ํจ์์ parameter๋ก ์ ์ํ๋ค. ์ฌ์ฉ์๊ฐ ์
๋ ฅ ํ๋์ ๋ค๋ฅธ ์ด๋ฆ์ ์
๋ ฅํ์ฌ
๋ชจ๋ธ์ ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํ๋ฉด Formatter๊ฐ ํ๋ ์์ํฌ์ ์ํด ์๋์ผ๋ก ํธ์ถ๋๋ค. ์ด๋ ๊ฒ ํ๋ฉด UI๊ฐ ๋ฐ์ดํฐ ๋ชจ๋ธ๊ณผ ๋๊ธฐํ๋๋ค.
<Link href="{
parts: [
'/firstName',
'/lastName'
],
formatter: '.formatMail'
}"
text="{i18n>sendEmail}"/>
complex bindings์ ๊ฒฝ์ฐ {}
์ ํจ๊ป simple binding syntax๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
Link element์ href ํ๋กํผํฐ๋ ๋ฌธ์์ด ๊ฐ ์์ ์ ์ฒด ๊ฐ์ฒด๋ฅผ ํฌํจํ๋ค. ์ด ๊ฒฝ์ฐ ๊ฐ์ฒด์๋ ๋ ๊ฐ์ง ํ๋กํผํฐ๊ฐ ์๋ค.
1. parts
parts๋ ๊ฐ ์์๊ฐ ๊ฒฝ๋ก ์์ฑ์ ํฌํจํ๋ ๊ฐ์ฒด์ธ Javascript ๋ฐฐ์ด์ด๋ค. ์ด ๋ฐฐ์ด์ ์์ ์์ ์์๋ formatMail function์ ๋งค๊ฐ๋ณ์์ ์์์ ๊ฐ๋ค.
2. formatter
parts ๋ฐฐ์ด์ ๋์ด๋ parameters๋ฅผ ์์ ํ๋ function์ ๋ํ reference์ด๋ค. formatter ํจ์์ ์ํด ๋ฐํ๋๋ ๋ชจ๋ ๊ฐ์ ์ด ์์ฑ์ ์ค์ ๋ ๊ฐ์ด๋ค.
๐ก ํฌ๋งทํฐ ์์ ๋ถ๋ถ์ ์ (formatMail)์ ํ์ฌ View์ Controller Instance์์ fromatMail ํจ์๋ฅผ ์ฐพ๋๋ก SAPUI5์ ์ ์ง์ํ๋ค.
์ ์ ์ฌ์ฉํ์ง ์๋ ๊ฒฝ์ฐ ์ ์ญ ๋ค์์คํ์ด์ค๋ฅผ ๊ฒ์ํ์ฌ ํจ์๋ฅผ ํ์ธํ๋ค.
formatter functions์ ์ฌ์ฉํ ๋ binding์ ์๋์ผ๋ก 'one-way'๋ก ์ ํ๋๋ค. ๋ฐ๋ผ์ 'two-way' ์๋๋ฆฌ์ค์๋ ํฌ๋งทํฐ ๊ธฐ๋ฅ์ ์ฌ์ฉํ ์ ์์ง๋ง data types์ ์ฌ์ฉํ ์ ์๋ค.
sendEmail=Send Mail
mailSubject=Hi {0}!
mailBody=How are you?