跳到主要内容

公式

规格​

标签值
版本1.9.0(更新于 2025-08-08)
开发者Labii Inc.
类型列
支持配置是
支持只读视图是
支持编辑视图否
支持表单视图否
支持默认值否
支持导入否
允许多个是

概述​

Formula 小插件让用户可以在应用界面中使用 JavaScript 公式创建自定义计算。此动态工具可无缝使用当前记录的数据,执行符合特定上下文的精确计算。它还可以通过 ForeignKey 关系获取关联记录中的值,让用户能够灵活构建跨数据集的综合计算。无论是创建复杂的财务模型还是改进数据分析,Formula 小插件都能为需要在应用工作流程中使用自定义计算的用户提供灵活方案。

使用场景​

  • 计算样品的剩余体积。
  • 计算 RT-PCR 结果的检测状态。

配置​

要使用此小插件,需要提供相应选项。

  • Data of Foreign Record(s) - 配置公式中要使用的外部记录数据。
    • Foreign columns - 外部记录由使用 ForeignKey、ForeignKeys、NestedFields 或 ColumnData 的列定义。
  • Data of Origin Record(s) - 配置公式中要使用的来源记录数据。可以通过 data[column sid]: Array 引用这些数据。
    • Table (Origin) - 选择存储原始数据的表。
    • Column (Source) of the Origin table - 选择来源表中与当前记录关联的列。
    • Column (Value) of the Origin table - 选择来源表中与当前记录关联的列。
    • Origin Query - 添加补充查询条件,进一步筛选显示的记录。
  • Count Query - 如果要在公式中使用计数值,请提供一个或多个查询。可以通过 count[query name] 引用计数。
    • Query - 如果要在公式中使用计数值,请提供一个或多个查询。
  • Formula settings - 配置公式设置。
    • Formula - 语法:data[Field 1] + data[Field 2] + count[query name]
      • 公式字段还支持变量。
    • Highlight
      • Condition or value - 要突出显示的值或触发突出显示的条件。
        • Color
        • Method
          • Background
          • Text
    • Execute after - 选择在触发此公式之前需要执行的公式列。当公式依赖另一个公式生成的值时,应使用此字段。
    • Stop condition - 条件满足时,公式停止计算。条件必须返回 true 或 false。此字段不支持其他列数据,只能使用变量 data 引用当前记录数据。
    • Should auto update when readonly - 选中后,此小插件会在只读状态下执行实时计算。
    • Should enable manual edit - 选中后,此小插件允许手动编辑。

示例​

{
"columns": [ # (optional),
{"sid":"xxx", "name":"xxx"}, # The column sid of ForeignKey, ForeignKeys, NestedFields, optional
],
"queries": [ # (optional)
{
"name": "xxx",
"table": {"sid":"xxx", "name":"xxx"},
"query": "name=xxx"
}
],
"formula": "", # (required), the formula, see the Syntax below
# data[column_sid], value of a column of current row
# data[row_sid__column_sid], value of column of a fixed row
# data[`${data['column__sid'].sid}`__column_sid]
# data[column1_sid__column2_sid], column1_sid, the ForeignKey column listed in rows;
# data[column1_sid__column2_sid] of ForeignKeys returns array of data.
# count[table_sid__column_sid], the count value
"after": [], # Select the formula columns that need to be executed before this formula is triggered.
# When a formula is based on a value generated by another formula, this field should be used.
"format": {}, # (optional), the number in the wNumb format.
# Learn more at https://refreshless.com/wnumb/
"should_auto_update": false, # (optional), default to false.
# If true, the widget will perform live calculation
# If false, the user have to click reload to update the value
"should_auto_update_when_empty": true, # (optional), default to true.
# If true, the widget will perform live calculation when the data is empty
# If false, the results will not be calculated on default
}

使用公式返回记录名称

formula = `return "{{NAME}}"`

视图​

在以下视图中查看此小插件的界面。

只读视图​

只读视图显示列的值。

编辑视图​

编辑视图是用于修改值的界面。

此小插件不支持编辑视图。

表单视图​

表单视图是集成到添加表单中的字段,用于在创建新记录时收集值。

此小插件不支持表单视图。

数据​

Labii 中的每个小插件都以独特的方式存储数据;请参阅以下内容,了解此小插件的数据存储方式。

数据格式​

公式返回的任意数据。

默认值​

列中的 Default Value 字段允许您指定创建记录时使用的默认值。

默认值可以是任意字符串。

导入值​

Import Value 是需要包含在 Excel 表格中的值,以便将其导入 Labii。

导入值可以是任意字符串。