amis icon indicating copy to clipboard operation
amis copied to clipboard

期望支持自定义公式,类似自定义过滤器

Open thinkingc opened this issue 1 year ago • 2 comments

是否关联于某个问题吗:

过滤器已经不推荐使用,推荐使用表达式,但没有办法自定义公式,还是要自定义过滤器实现。

https://baidu.github.io/amis/zh-CN/docs/concepts/expression#%E5%85%AC%E5%BC%8F

预期的解决方案:

期望支持自定义公式。比如

import { registerFunction } from 'amis'

registerFunction('CUSTOM_SUM', (a, b, fn) => { return  fn(a) + fn(b) }

{
tpl: "CUSTOM_SUM(1,2, item => item * -1)"
}

其他可接受方案:

任何附加信息:

thinkingc avatar Sep 05 '24 06:09 thinkingc

👍 Thanks for this! 🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

github-actions[bot] avatar Sep 05 '24 06:09 github-actions[bot]

https://github.com/baidu/amis/blob/8ac45be9ec0880832b981768f3871f797728daeb/packages/amis-formula/src/index.ts#L28 在 amis-formula 中 import { registerFunction } from 'amis-formula'

allenve avatar Sep 27 '24 06:09 allenve

这种方式定义的函数,无法关联到variable

aFcFzF avatar Jul 02 '25 08:07 aFcFzF