@idealworld/formula-editor v0.6.2 / iwExecutor / execute
Function: execute()
execute(
inputParams
,formulaValue
,materials
,entrance
):Promise
<any
>
Formula execution engine
Parameters
• inputParams: Map
<string
, any
>
input parameters
• formulaValue: string
the formula to be executed
• materials: Namespace
[]
materials used in the formula. You need to ensure that the variables or functions used in the formula are defined, and the variables in materials have corresponding input params values.
• entrance: string
entrance variable of the formula
Returns
Promise
<any
>
formula execution results
Example
js
let inputParams = new Map<string,any>()
inputParams.set('$.field.age', 18)
let formulaValue = `$.fun.concat($.fun.sum(1,$.field.age))`
let entrance = '$'
let materials = [
{
name: 'field',
label: '字段',
isVar: true,
items: [
{
name: 'applicant',
label: '申请人'
},
{
name: 'age',
label: '年龄'
}
]
},
{
name: 'fun',
label: '内置',
isVar: false,
items: [
{
name: 'sum',
label: '求和',
body: `return Array.from(arguments).reduce((a, b) => a + b)`
},
{
name: 'concat',
label: '合并文本',
body: `return Array.from(arguments).join('')`
]
}]
try{
let result = await execute(inputParams, formulaValue, materials, entrance)
}catch(e){
console.error(e)
throw e
}