跳转至

Struct variables(结构变量(Struct variables))

A struct variable is a composite variable containing fields of other Workshop-supported variable types. Nested structs are currently not supported.

Create a struct variable

A struct variable can be initialized statically within Workshop, using an object's struct property, or with a function that returns a CustomType. Refer to the custom types documentation to learn more. If a field's type is not supported in Workshop, it will be ignored and omitted from the initialized variable.

Struct creation using a function

Create a struct array variable

Similarly, a struct array variable containing multiple structs can be initialized using an object's struct array property, or a function.

Struct array creation using a function

Looping over struct arrays

Struct array variables may be used in loop layouts to enable more performant looping setups in applications with fewer load calls needed to display objects data, or in workflows where a builder may want to display non-ontologized data outputted with a function. To learn more about looping over arrays, refer to loop layout documentation.

Extract a field from a struct

Widgets and variable transformation operations cannot use structs as a whole, so individual struct fields must be extracted for use. The image below shows how the string type name field is extracted from the person struct variable using an extract struct field variable transform, and then used in a Metric card widget.

Extracting a "name" field from a "person" struct

Use structs as function inputs

Struct and struct array variables can also be used as inputs to functions. When configuring a function that uses a struct as an input, the required fields of the struct input may be previewed by hovering over the Preview schema label. This enables builders to verify that the expected input schema matches that of the selected struct variable by referencing it to the struct variable's raw Current value.

An example of a struct as a function input


中文翻译


结构变量(Struct variables)

结构变量(struct variable) 是一种复合变量,包含Workshop支持的其他变量类型(variable types)对应的字段。目前暂不支持嵌套结构。

创建结构变量

您可以在Workshop内静态初始化结构变量,也可以使用对象(Object)的结构属性,或是返回CustomType的函数来完成初始化。如需了解更多信息,请参考自定义类型(custom type)文档。如果某个字段的类型不受Workshop支持,该字段会被忽略,不会包含在初始化后的变量中。

使用函数创建结构

创建结构数组变量

同理,包含多个结构的结构数组变量(struct array variable) 可以通过对象的结构数组属性或是函数来初始化。

使用函数创建结构数组

遍历结构数组

结构数组变量可用于循环布局,减少展示对象数据所需的加载调用次数,让应用中的循环配置性能更优;也可用于构建者想要展示函数输出的非本体(non-ontologized)数据的工作流中。如需了解更多关于数组遍历的内容,请参考循环布局文档

从结构中提取字段

组件(Widget)和变量转换操作无法直接使用完整的结构,因此必须先提取出单个结构字段才能使用。下图展示了如何通过提取结构字段变量转换(extract struct field variable transform),从person结构变量中提取字符串类型的name字段,之后在指标卡组件(Metric card widget)中使用该字段。

从"person"结构中提取"name"字段

将结构用作函数输入

结构和结构数组变量也可以作为函数的输入。配置以结构作为输入的函数时,将鼠标悬停在Preview schema标签上即可预览结构输入的必填字段。构建者可以将预期的输入模式与所选结构变量的原始当前值(Current value)进行比对,验证二者是否匹配。

结构作为函数输入的示例