了解数据卡Understand data cards

控件是编辑表单显示表单控件的构建基块。Card controls are the building blocks of the Edit form and Display form controls. 表单表示整条记录,每个卡表示该记录的单个字段。The form represents the entire record, and each card represents a single field of that record.

在设计工作区中选择表单控件后即可在右窗格中与卡轻松地进行交互。You can interact with cards most easily in the right-hand pane after you select a form control in the design workspace. 在该窗格中,可以选择要显示哪些字段、每个字段的显示方式,以及按何种顺序进行显示。In that pane, you can choose which fields to show, how to show each field, and in what order to show them. 此示例显示了从名为“资产”的 SharePoint 列表生成的应用中的“编辑表单”控件。This example shows an Edit form control in an app built from a SharePoint list that's named Assets.

若要开始使用卡,请参阅添加表单了解数据表单To get started with cards, see add a form and understand data forms. 本主题的剩余内容将更详细地介绍卡的工作方式以及你可以如何自定义卡甚至创建自己的卡。The remainder of this topic goes into more detail about how cards work and how you can customize or even create your own.

预定义的卡Predefined cards

PowerApps 为字符串、数字和其他数据类型提供了一组预定义的卡。PowerApps offers a predefined set of cards for strings, numbers, and other data types. 在右侧窗格中,你可以看到可用的变体,并可更改用于某个字段的卡:In the right-hand pane, you can see the variations available and change the card used for a field:

在本例中,选择了一个单行文本卡,但 URL 的文本的长度超出了可以在单行中显示的长度。In this example, a single-line text card is selected, but the URL's text is longer than can be shown on a single line. 让我们将此卡更改为一个多行文本卡,以便为我们的用户提供更多的空间进行编辑:Let's change this to a multi-line text card to give our users more room to edit:

此数据源的多个字段均不会显示,但是可以通过选择字段的复选框来显示或隐藏它。Several fields of this data source aren't being shown, but you can show or hide a field by selecting its checkbox. 此示例演示了如何显示 SecurityCode 字段。This example illustrates how to show the SecurityCode field.

自定义卡片Customize a card

卡还包含其他控件。Cards comprise other controls. 在“编辑表单”控件中,用户在你从“插入”选项卡添加的标准文本输入控件中输入数据。In an Edit form control, the user enters data in a standard Text input control that you add from the Insert tab.

下面,让我们举例说明如何通过操作其中的控件来更改卡的外观。Let's walk through an example of how to change a card's appearance by manipulating controls in it.

  1. 首先,让我们返回到最近为 SecurityCode 字段插入的卡。First, let's return to the card that we inserted most recently, for the SecurityCode field. 通过单击或点击一次来选择此卡:Select this card by clicking or tapping it once:

  2. 选择该卡内的文本输入控件(通过单击或点击输入控件本身)。Select the Text input control inside the card by clicking or tapping the input control itself.

  3. 通过拖动选择框在卡内移动此控件,通过沿选择框的边缘拖动手柄来调整控件大小:Move this control within the card by dragging the selection box, and resize the control by dragging the handles along the edge of the selection box:

你可以调整卡中控件的大小、移动控件或者对其进行其他修改,但在不先解锁控件的情况下无法将其删除。You can resize, move, and make other modifications to controls within a card, but you can't delete it without unlocking it first.

解锁卡Unlock a card

除了可以包含控件之外,卡本身也是控件,与任何其他控件一样,它们也具有属性和公式。In addition to containing controls, cards themselves are controls that have properties and formulas just like any other control. 当你选择在表单上显示某个字段时,右侧的窗格会自动为你创建卡并生成所需的公式。When you choose to display a field on a form, the right-hand pane automatically creates the card for you and generates the needed formulas. 可以在右窗格的“高级”选项卡中看到这些公式:We can see these formulas in the Advanced tab of the right-hand pane:

我们会立即看到卡的最重要属性之一:DataField 属性。We immediately see one of the most important properties of the card: the DataField property. 此属性指示用户在此卡中可以看到和编辑数据源的哪个字段。This property indicates which field of the data source the user sees and can edit in this card.

在“高级”选项卡上,顶部的横幅指示此卡的属性处于锁定状态。On the Advanced tab, the banner at the top indicates that the properties of this card are locked. DataFieldDisplayNameRequired 属性旁边还会显示一个锁图标。A lock icon also appears next to the DataField, DisplayName, and Required properties. 右侧窗格创建了这些公式,锁可以防止意外更改这些属性。The right-hand pane created these formulas, and the lock prevents accidental changes to these properties.

单击或点击顶部的横幅可以解锁卡以便修改这些属性:Click or tap the banner at the top to unlock the card so that you can modify these properties:

让我们来修改 DisplayName,在 AssetID 之间放置一个空格。Let's modify the DisplayName to put a space between Asset and ID. 通过执行此更改,我们更改了为我们生成的内容。By making this change, we're altering what was generated for us. 在右侧窗格中,此卡有一个不同的标签:In the right-hand pane, this card has a different label:

现在,我们已经取得了此卡的控制权,可以进一步修改它来满足我们的需求。We've now taken control over this card and can modify it further to fit our need. 但是,我们已无法像之前那样将卡从一种表示形式更改为另一种表示形式,例如,从单行文本更改为多行文本。But we've lost the ability to change the card from one representation to another (for example, single-line text to multi-line text) as we did before. 我们已经将此预定义的卡转变为现在由我们控制的一个“自定义卡”。We've transformed the predefined card into a "custom card" that we now control.

重要说明:无法重新锁定你已解锁的卡。Important: You can't relock a card if you unlock it. 要想将卡恢复为锁定状态,需要先将其删除,然后在右侧窗格中将其重新插入。To get a card back to a locked state, remove it, and reinsert it in the right-hand pane.

可以使用很多方法来更改已解锁卡的外观和行为,例如添加和删除其中的控件。You can change the appearance and behavior of an unlocked card in a variety of ways, such as adding and deleting controls within it. 例如,可以从“插入”选项卡上的“图标”菜单中添加星形。For example, you can add a star shape from the Icons menu on the Insert tab.

此星形现在已成为卡的一部分,并且将随它一起移动,例如当你在表单内重新排列卡时。The star is now a part of the card and will travel with it if, for example, you reorder the cards within the form.

再如,将 ImageURL 卡解锁,然后从“插入”选项卡将“图像”控件添加到其中:As another example, unlock the ImageURL card, and then add an Image control to it from the Insert tab:

在编辑栏中,将此控件的 Image 属性设置为 TextBox.Text,其中 TextBox 是保存 URL 的“文本输入”控件的名称:In the formula bar, set the Image property of this control to TextBox.Text, where TextBox is the name of the Text input control that holds the URL:

提示:按 Alt 键可以显示每个控件的名称。Tip: Press the Alt key to show the name of each control.

现在,我们可以看到图像并编辑其 URL 了。And now we can see the images and edit their URLs. 注意,我们也可以使用 Parent.Default 作为 Image 属性,但当用户更改 URL 时它不会更新。Note that we could have used Parent.Default as the Image property, but it wouldn't have updated if the user changed the URL.

我们可以在此应用的第二个屏幕上执行同样的操作,其中,我们将使用“显示表单”控件来显示记录的详细信息。We can do the same thing on the second screen of this app, where we use a Display form control to display the details of a record. 此时,我们不妨隐藏标签(将标签(而不是卡)的 Visible 属性设置为 false),因为用户不会在此屏幕上编辑 URL:In this case, we may want to hide the label (set the Visible property of the label, not the card, to false) because the user won't edit the URL on that screen:

与表单进行交互Interact with a form

在解锁卡后,你可以更改它与包含它的表单进行交互的方式。After you unlock a card, you can change how it interacts with the form that contains it.

下面是有关控件应当如何与其卡配合使用以及卡应当如何与表单配合使用的一些指导原则。Below are some guidelines for how controls should work with their card and how the cards should work with the form. 它们只是指导原则。These are only guidelines. 对于 PowerApps 中的任何控件,你可以创建引用 PowerApps 中的任何其他控件的公式,对于卡和卡中的控件也是如此。As with any control in PowerApps, you can create formulas that reference any other control in PowerApps, and that's no less true for cards and controls within cards. 要有创造性:你可以通过许多方式创建应用。Be creative: you can create an app in many ways.

DataField 属性DataField property

卡上最重要的属性是 DataField 属性。The most important property on the card is the DataField property. 此属性驱动着验证、要更新的字段以及卡的其他方面。This property drives validation, what field is updated, and other aspects of the card.

流入的信息Information flowing in

作为容器,表单向其内的所有卡提供了 ThisItemAs a container, the form makes ThisItem available to all cards within it. 此记录包含所关注的当前记录的所有字段。This record contains all of the fields for the current record of interest.

每个卡的 Default 属性都应当设置为 ThisItem. FieldNameThe Default property of every card should be set to ThisItem.FieldName. 某些情况下,你可能希望在来途中转变此值。Under certain circumstances, you might want to transform this value on the way in. 例如,你可能希望设置字符串的格式或者将值从一种语言翻译为另一种语言。For example, you might want to format a string or translate the value from one language to another.

卡内的每个控件都应当引用 Parent.Default 来获取字段的值。Each control within the card should reference Parent.Default to get at the field's value. 此策略为卡提供了一定程度的封装,以便卡的 Default 属性可以在不更改卡的内部公式的情况下进行更改。This strategy provides a level of encapsulation for the card so that the card's Default property can change without changing the internal formulas of the card.

默认情况下,DefaultValueRequired 属性是基于 DataField 属性从数据源的元数据获取的。By default, DefaultValue and Required properties are taken from the data source's metadata based on the DataField property. 你可以使用自己的逻辑替代这些公式,通过使用 DataSourceInfo 函数集成数据源的元数据。You can override these formulas with your own logic, integrating the data source's metadata by using the DataSourceInfo function.

流出的信息Information flowing out

在用户使用卡中的控件修改记录后,SubmitForm 函数会将这些更改保存到数据源。After the user modifies a record by using controls in the cards, the SubmitForm function saves those changes to the data source. 当该函数运行时,表单控件将读取每个卡的 DataField 属性的值来了解要更改哪个字段。When that function runs, the form control reads the values of each card's DataField property to know what field to change.

表单控件还会读取每个卡的 Update 属性的值。The form control also reads the value of each card's Update property. 此值将存储在此字段的数据源中。This value will be stored in the data source for this field. 这是要应用另一个转换的地方,也许要反转在卡的 Default 公式中应用的转换。This is the place to apply another transform, perhaps to reverse the transform that was applied in the card's Default formula.

Valid 属性是基于 DataField 属性从数据源的元数据驱动的。The Valid property is driven from the metadata of the data source, based on the DataField property. 它还取决于 Required 属性以及 Update 属性是否包含值。It's also based on the Required property and whether the Update property contains a value. 如果 Update 属性上的值无效,则 Error 属性会提供一条用户友好错误消息。If the value on the Update property isn't valid, the Error property provides a user-friendly error message.

如果某个卡的 DataField 属性为 ,则说明该卡只是控件的容器。If the DataField property of a card is blank, the card is just a container of controls. ValidUpdate 属性在提交表单时不会参与。Its Valid and Update properties don't participate when the form is submitted.

剖析示例Dissecting an example

让我们看一下构成基本的数据输入卡的控件。Let's look at the controls that make up a basic data-entry card. 可以增大控件之间的空间以便更清晰地显示每个控件:The space between controls has been increased to show each more clearly:

按下 Alt 键来显示构成此卡的控件的名称:Hold down the Alt key to show the names of the controls that make up this card:

四个控件使得此卡可以工作:Four controls make this card work:

名称Name 类型Type 说明Description
TextRequiredStarTextRequiredStar 标签”控件Label control 显示一个星号,这通常在数据输入表单上用来指示某个字段是必填的。Displays a star, which is commonly used on data-entry forms to indicate that a field is required.
TextFieldDisplayNameTextFieldDisplayName 标签”控件Label control 显示此字段的用户友好名称。Displays the user-friendly name of this field. 此名称可以不同于数据源的架构中的名称。This name can differ from what is in the data source's schema.
InputTextInputText 输入文本控件Input text control 显示字段的初始值并允许用户更改该值。Displays the initial value of the field and allows the user to change that value.
TextErrorMessageTextErrorMessage 标签”控件Label control 如果验证时出现问题,则向用户显示一条用户友好错误消息。Displays a user-friendly error message to the user if a problem occurs with validation. 如果字段为必填字段,还可以确保字段具有值。Also ensures that the field has a value if one is required.

若要为这些控件填充数据,可以通过以下关键公式从卡的属性驱动其属性。To populate these controls with data, their properties can be driven from the properties of the card, through these key formulas. 注意,这些公式中没有一个引用特定的字段。Note that none of these formulas refers to a specific field. 相反,所有信息都来自卡。Instead, all information comes from the card.

控件属性Control property 公式Formula 说明Description
TextRequiredStar.VisibleTextRequiredStar.Visible Parent.RequiredParent.Required 只有当字段为必填字段时,星星才会显示。The star appears only if the field is required. Required 是由你或数据源的元数据驱动的一个公式。Required is a formula that's driven by you or the metadata of the data source.
TextFieldDisplayName.TextTextFieldDisplayName.Text Parent.DisplayNameParent.DisplayName 此文本框控件显示用户友好名称,这是由你或数据源的元数据提供的,并且是在卡的 DisplayName 属性中设置的。The text-box control shows the user-friendly name, which you or the data source's metadata provides, and which is set on the card's DisplayName property.
InputText.DefaultInputText.Default Parent.DefaultParent.Default 此文本输入控件最初显示来自数据源的由卡的默认值提供的字段值。The text-input control initially shows the value of the field from the data source, as provided by the card's default value.
TextErrorMessage.TextTextErrorMessage.Text Parent.ErrorParent.Error 如果发生验证问题,则卡的 Error 属性会提供一条合适的错误消息。If a validation problem occurs, the card's Error property provides an appropriate error message.

为了从这些控件中提取信息并将其推送回数据源,我们提供了以下关键公式:To pull information out of these controls and push it back into the data source, we have the following key formulas:

控件名称Control name 公式Formula 说明Description
DataCard.DataFieldDataCard.DataField "ApproverEmail""ApproverEmail" 用户可以在此卡中显示和编辑的字段的名称。The name of the field that the user can display and edit in this card.
DataCard.UpdateDataCard.Update InputText.TextInputText.Text SubmitForm 运行时要验证并推送回数据源的值。The value to validate and push back into the data source when SubmitForm runs.