API Reference > @next-core/brick-kit > looseCheckIfByTransform
looseCheckIfByTransform() function
给定一个数据源,根据表达式计算条件判断的结果。
Signature:
export declare function looseCheckIfByTransform(
ifContainer: IfContainer,
data: unknown,
options?: Pick<DoTransformOptions, "allowInject" | "tplContextId">
): boolean;
Parameters
| Parameter | Type | Description |
|---|---|---|
| ifContainer | IfContainer | 包含 if 条件判断的配置对象。 |
| data | unknown | 要传递的数据源。 |
| options | Pick<DoTransformOptions, "allowInject" | "tplContextId"> | allowInject 允许在 if 中使用 ${...} 占位符。 |
Returns:
boolean
条件判断的结果。
Remarks
当 ifContainer 中没有出现 if 字段时,则认为条件判断为 true。
而如果 if 为表达式字符串时,将根据给定的数据源 data 进行 transform,并返回转换为 boolean 类型后的结果。
Example 1
const brickConf = {
if: "<% DATA.list.length > 0 %>",
brick: "your.any-brick",
};
const data = { list: [] };
const result = looseCheckIfByTransform(brickConf, data);
// Returns false.
Example 2
const brickConf = {
if: "<% DATA.list.length %>",
brick: "your.any-brick",
};
const data = { list: [1, 2] };
const result = looseCheckIfByTransform(brickConf, data);
// Returns true.
Example 3
const brickConf = {
brick: "your.any-brick",
};
const result = looseCheckIfByTransform(brickConf, data);
// Returns true.