sapui5 中的 parts: 和 path: 是什么以及为什么使用它们?

Aay*_*shk 0 sapui5

SAPUI5中处理模型时partsand有什么用?path

有人可以解释一下以下代码(invoiceJSONModel 在哪里)吗?

<mvc:View
    controllerName="sap.ui.demo.walkthrough.controller.InvoiceList"
    xmlns="sap.m"
    xmlns:mvc="sap.ui.core.mvc">
    <List
            headerText="{i18n>invoiceListTitle}"
        class="sapUiResponsiveMargin"
        width="auto"
        items="{invoice>/Invoices}">
        <items>
            <ObjectListItem
                title="{invoice>Quantity} x {invoice>ProductName}"
                number="{
                    parts: [{path: 'invoice>ExtendedPrice'}, {path: 'view>/currency'}],
                    type: 'sap.ui.model.type.Currency',
                    formatOptions: {
                        showMeasure: false
                    }
                }"
                numberUnit="{view>/currency}"
                numberState="{= ${invoice>ExtendedPrice} > 50 ? 'Error' : 'Success' }">
                <firstStatus>
                    <ObjectStatus text="{
                        path: 'invoice>Status',
                        formatter: '.formatter.statusText'
                    }"/>
                </firstStatus>
            </ObjectListItem>

        </items>
    </List>
</mvc:View>
Run Code Online (Sandbox Code Playgroud)

Ser*_*scu 5

欢迎来到 StackOverflow!

您所引用的称为“绑定”。在您的示例中,您有:

  • 列表绑定:items="{invoice>/Invoices}".
  • 简单的属性绑定:numberUnit="{view>/currency}".
  • 复合属性绑定:(number="{parts: [...]}使用显式语法)和title="{invoice>Quantity} x {invoice>ProductName}"(使用复杂语法)。
  • 表达式绑定:numberState="{= ${invoice>ExtendedPrice} > 50 ? 'Error' : 'Success' }"

SDK 在“数据绑定”一章下有一些关于这些主题的详细文档页面。

列表绑定用于基于模型内的数据(基于对象列表或对象映射)创建控件集合。从概念上讲,您可以想象 UI5 循环遍历您的值并使用模板或工厂函数实例化相应的控件。本例中的路径是指向集合的(相对或绝对)路径

简单属性绑定仅用于根据模型中的单个标量字段填充模型中控件的属性。这里的路径是指向该属性的(相对或绝对)路径

复合属性绑定可用于填充基于多个字段的控件属性,这些字段通过格式化程序函数或类型(如示例中的货币)组合。例如,当使用格式化程序时,每个都part将作为参数传递给您的函数(例如,如果您有 2 个部分,则您的格式化程序应该有 2 个参数)。此处的部分用于定义计算属性值时要使用的每个单独字段。

表达式绑定或复杂语法只是语法糖的一种形式,允许您内联定义格式化程序,而无需编写专用的 JS 函数。

您始终可以使用简化语法property="{/path}"或扩展语法property="{path: '/path'}",它们是等效的(但是一旦您想要指定更多绑定参数,您就被迫使用扩展语法)。