Expression binding을 사용하면 일부 model 객체에서 발견된 값에서 계산된 값을 화면에 표시할 수 있다.
이렇게 하면 간단한 포맷이나 계산을 데이터 바인딩 문자열에 직접 삽입할 수 있다.
이 예에서는 임의의 임계값보다 높거나 낮거나에 따라 가격 색상을 변경한다. 임계 값은 JSON Model에도 저장된다.
<ObjectListItem title="{products>ProductName}" number="{
parts: [
{path: 'products>UnitPrice'},
{path: '/currencyCode'}
],
type: 'sap.ui.model.type.Currency',
formatOptions: { showMeasure: false }
}" numberUnit="{/currencyCode}" numberState="{= ${products>UnitPrice} > ${/priceThreshold} ? 'Error' : 'Success' }" press=".onItemSelected" type="Active">
...
/>
// model
{
priceThreshold: 20,
currencyCode: "EUR"
};
다양한 expression binding 활용은 다음 사이트를 참조해라.
numberState="{= ${products>UnitPrice} > ${/priceThreshold} ? 'Error' : 'Success' }"
numberState="{= ${products>UnitPrice} <= ${/priceThreshold} ? 'Success' : 'Error' }"
XML parser에서 우선순위가 높은 문자 중 하나(<
)를 발견하는 즉시, 문자가 표현식의 컨텍스트 내에 있을 수 있는 다른 의미와
상관없이 항상 새 XML 태그의 시작으로 해석된다. 이를 구문 충돌이라고 한다.
Use the escaped value for the less-than character
numberState="{= ${products>UnitPrice} <= ${/priceThreshold} ? 'Success' : 'Error' }"
또한 &
문자는 XML parser에서 높은 우선 순위를 가진다. 이 문자는 항상 'The start of an escaped character'을 의미하는 것으로 해석된다.
따라서 AND 연산자(&&
)를 사용하려면 두 ampersand 문자를 모두(&&
) escape 해야 한다.