๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Fiori/UI5

[UI5] Aggregation Binding

by clode 2023. 3. 7.
728x90
๋ฐ˜์‘ํ˜•

๐Ÿ™„ invoice๋ฅผ ์ƒ์„ฑํ•ด๋ณด์ž.

App.view.xml

<mvc:XMLView viewName="sap.ui.demo.walkthrough.view.Invoicelist" />

InvoiceList.view.xml

viewํด๋”์—์„œ ์ƒˆ๋กœ์šด ํŒŒ์ผ InvoiceList.view.xml์„ ์ƒ์„ฑํ•œ๋‹ค.

<mvc:View
    xmlns="sap.m"
    xmlns:mvc="sap.ui.core.mvc">
    <List
        headerText="{i18n>invoiceListTile}"
        class="sapUiResponsiveMargin"
        width="auto"
        items="{invoice>/Invoices}" >
        <items>
            <ObjectListItem
                title="{invoice>Quantity} x {invoice>ProductName}" />
        </items>
    </List>    
</mvc:View>

List ๋ชจ๋“ˆ์€ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“ˆ์ด๊ธฐ ๋•Œ๋ฌธ์— invoice๋ผ๋Š” ๋ชจ๋ธ์•ˆ์˜ Invoices ํ”„๋กœํฌํ‹ฐ๋กœ ๋ฐฐ์—ด๋กœ ๋œ ๋ฐ์ดํ„ฐ Invoices๋ฅผ ๋ฐ”์ธ๋”ฉ ํ•ด์ค€๋‹ค.

๊ทธ๋Ÿผ ํ˜„์žฌ List์˜ items์—๋Š” ๋ฐฐ์—ด Invoices๊ฐ€ ๋ฐ”์ธ๋”ฉ ๋˜์–ด์žˆ๋Š”๋ฐ, ๋ฐ”์ธ๋”ฉ๋œ ๋ฐฐ์—ด์•ˆ์— ๊ฐ์ฒด๋“ค์ด ์žˆ๋‹ค. aggregation์•ˆ์— ์žˆ๋Š” ๋ชจ๋“ˆ์ด ๋ฐ˜๋ณต๋˜๋ฉด์„œ ๊ฐ์ฒด๋ฅผ ์ˆœ์„œ๋Œ€๋กœ ํ•˜๋‚˜์”ฉ ๊ฐ€์ ธ์˜ค๊ฒŒ ๋œ๋‹ค.

๋ฐฐ์—ด์‚ฌ์šฉํ•˜๋Š” ๋ชจ๋“ˆ์—๋Š” List, Table, Select, ComboBox๊ฐ€ ์žˆ๋‹ค. ์ด ๋ชจ๋“ˆ๋“ค์€ ๋ฐฐ์—ด๋กœ ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ”์ธ๋”ฉ ํ•ด์ค˜์•ผ ํ•˜๊ณ  aggregation ๋ถ€๋ถ„์„ length๋งŒํผ ๋ฐ˜๋ณต์‹œํ‚จ๋‹ค. for๋ฌธ์œผ๋กœ ์ธ์‹ํ•˜๋ฉด ์ดํ•ด๊ฐ€ ์‰ฝ๋‹ค.

{invoice>Quantity} ๋ฐฐ์—ด์•ˆ์— ๋“ค์–ด์žˆ๋Š” ๊ฐ์ฒด์˜ ํ”„๋กœํฌํ‹ฐ ๊ฐ’์„ ๊ฐ€์ ธ์˜จ๋‹ค.

๋ฐ˜๋ณต๋˜๋Š” ๋ชจ๋“ˆ์•ˆ์—์„œ๋Š” /๋ฅผ ์ƒ๋žตํ•œ๋‹ค.

i18n_ko.properties

์ธ๋ณด์ด์Šค์˜ ํƒ€์ดํ‹€์„ ์ž…๋ ฅํ•œ๋‹ค.

invoiceListTile=Invoices


๐Ÿ˜Š ๋ฐ์ดํ„ฐ๋ฅผ ๋„ฃ์–ด๋ณด์ž.

์•„์ดํ…œ์˜ title์„ "{invoice>Quantity} x {invoice>ProductName}"๋กœ ํ•ด๋†จ๊ธฐ ๋•Œ๋ฌธ์— Quantity x ProductName์œผ๋กœ ๋‚˜์˜ค๋Š”๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

invoices.json

์ƒˆ๋กœ jsonํŒŒ์ผ์„ ๋งŒ๋“ค๊ณ  ํŒŒ์ผ์„ ์ƒˆ๋กœ ์ƒ์„ฑํ•œ๋‹ค.

{
  "Invoices": [
    {
      "ProductName": "Pineapple",
      "Quantity": 21,
      "ExtendedPrice": 87.2000,
      "ShipperName": "Fun Inc.",
      "ShippedDate": "2015-04-01T00:00:00",
      "Status": "A"
    },
    {
      "ProductName": "Milk",
      "Quantity": 4,
      "ExtendedPrice": 9.99999,
      "ShipperName": "ACME",
      "ShippedDate": "2015-02-18T00:00:00",
      "Status": "B"
    },
    {
      "ProductName": "Canned Beans",
      "Quantity": 3,
      "ExtendedPrice": 6.85000,
      "ShipperName": "ACME",
      "ShippedDate": "2015-03-02T00:00:00",
      "Status": "B"
    },
    {
      "ProductName": "Salad",
      "Quantity": 2,
      "ExtendedPrice": 8.8000,
      "ShipperName": "ACME",
      "ShippedDate": "2015-04-12T00:00:00",
      "Status": "C"
    },
    {
      "ProductName": "Bread",
      "Quantity": 1,
      "ExtendedPrice": 2.71212,
      "ShipperName": "Fun Inc.",
      "ShippedDate": "2015-01-27T00:00:00",
      "Status": "A"
    }
  ]
}

component.js

์ƒˆ๋กœ ์ƒ์„ฑํ•œ jsonํŒŒ์ผ์„ ์ฝ์–ด์˜ค์ž. initํ•จ์ˆ˜ ์•ˆ์— ๋กœ์ง์„ ์ถ”๊ฐ€ํ•œ๋‹ค.

         var that = this;

         $.ajax({
             url:"./json/Invoices.json",
             type: "get",
             success: function (oResult) {
                 var oInvoiceModel = new JSONModel(oResult);
                 that.setModel(oInvoiceModel, "invoice");
             }
         });

this๋Š” ๊ธฐ์กด๋กœ์ง์˜ UIComponent๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด success ํ•จ์ˆ˜ ๋ฐ–์—๋‹ค๊ฐ€ ์„ ์–ธํ•ด์ค€๋‹ค. this๋ฅผ ์–ด๋””์„œ ์‚ฌ์šฉํ•˜๋ƒ์— ๋”ฐ๋ผ this๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š”๊ฒŒ ๋‹ฌ๋ผ์ง€๋Š”๋ฐ successํ•จ์ˆ˜์—์„œ thisํ•˜๋ฉด ๋‹ค๋ฅธ์• ๋ฅผ ๊ฐ€๋ฆฌํ‚ค๊ฒŒ ๋œ๋‹ค.

ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ค๋Š”๋ฐ ์„ฑ๊ณตํ–ˆ์„์‹œ oResult์— ๋‹ด๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ๋ชจ๋ธ์— ๋‹ด์•„ ๋ชจ๋ธ์„ invoice ๋ทฐ์— ๋ฐ”์ธ๋”ฉํ•œ๋‹ค.


728x90
๋ฐ˜์‘ํ˜•

'Fiori > UI5' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[UI5] ์˜ˆ์ œ (๊ตฌ๊ตฌ๋‹จ)  (0) 2023.03.08
[UI5] Data types  (0) 2023.03.08
[UI5] Dialogs and Fragments  (0) 2023.03.07
[UI5] Pages, Panels, Shell, Margins, Nested View, Custom CSS  (0) 2023.03.07
[UI5] ํ™”๋ฉด ๊ฐœ์„   (0) 2023.03.07

๋Œ“๊ธ€