Comment on page
When you use an app or service, data is stored and manipulated using objects. An object is an instance of an object class, containing data that adheres to a defined structure. An object typically represents a single real world object like a customer, order, or order line. If you're familiar with databases, an object can be thought of as a row in a database table.
When developing there are cases where you need to be able to identify a single object, or a selection of objects, within a data source. To achieve that there are two concepts which are used individually and together: Object in context and Object selection. These two concepts enable you to explicitly state which object(s) to reference to when switching between UI and logic.
You have a List component bound to a data source called
Projects. For each item, you have a
Copy projectbutton that triggers an action to create a new project and set it as selected.
Copy projecton Project 1 will create Project 2 in the same data source. There is one object in context (Project 1) and one selected object (Project 2)
If you then try to create a
Projects (context/selected)the object in context, Project 1, will be assigned.
Good to know
- If you add an enum data source, object in context and object selection will also apply to those enums.
The object in context is the current object being processed in an iteration. This allows you to loop through a many-cardinality data source and reference the properties as though it contained a single object to display or modify the data inside. The following elements run iterations and produce an object in context.
- List and Table components These components have built-in iterators that loop through the data source they are bound to. The object in each list item or table row is the object in context.
- Iterating containers in the UI A container can be configured to iterate over a multi-cardinality data source. The contents of the container will be repeated for each object in the data source (subject to any filters). The object in each iteration is the object in context. For example, you have an iterating container bound to a data source called
Events, and a child Text component bound to
Events.Titleto list the name of every event.
- Foreach action node When the foreach loops through the objects in a data source, the action nodes placed inside the foreach will be run for each object, with each object taking a turn being the object in context. For example, you have a foreach iterating over a data source called
Event Attendeesand inside the foreach a Send email action node with the recipient bound to the
Event Attendees.Emailproperty, to send a ticket by email to each attendee.
An object in a many-cardinality data source can be selected. All objects in many-cardinality data sources have the built-in property Is Selected to track this flag. Any number of objects in a data source can be selected at the same time.
Object selection can be used to create a dynamic subset of objects in a data source or to select a single object. For example, you have a data source called
Eventsand you create a view with Text components bound to the properties
Events.Date. If you select a single object before navigating to the view, that object (event) will be used to populate the Text components.
This property, and its opposite Is Not Selected, can be referenced in a number of situations:
Data sources with selected objects are highlighted in the App data panel of the developer tools with a green tag. When a data source is selected, the number of selected objects is displayed above the table of objects and each selected object is marked with a check in the first column.