mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
feat: formula 扩充公式 ARRAYFILTER 用来做数组过滤 (#5554)
* publish beta * feat: formula 扩充公式 ARRAYFILTER 用来做数组过滤
This commit is contained in:
parent
67f839d18b
commit
19ee3ab674
@ -2,5 +2,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "2.3.1"
|
||||
"version": "2.3.2-beta.1"
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "amis-core",
|
||||
"version": "2.3.1",
|
||||
"version": "2.3.2-beta.1",
|
||||
"description": "amis-core",
|
||||
"main": "lib/index.js",
|
||||
"module": "esm/index.js",
|
||||
@ -43,7 +43,7 @@
|
||||
"esm"
|
||||
],
|
||||
"dependencies": {
|
||||
"amis-formula": "^2.3.1",
|
||||
"amis-formula": "^2.3.2-beta.1",
|
||||
"classnames": "2.3.1",
|
||||
"file-saver": "^2.0.2",
|
||||
"hoist-non-react-statics": "^3.3.2",
|
||||
|
@ -459,4 +459,11 @@ test('evalute:array:func', () => {
|
||||
{id: 1.1},
|
||||
{id: 2.2}
|
||||
]);
|
||||
|
||||
expect(evaluate('${ARRAYFILTER(arr1, item => item)}', data)).toMatchObject([
|
||||
1, 2, 3
|
||||
]);
|
||||
expect(
|
||||
evaluate('${ARRAYFILTER(arr1, item => item && item >=2)}', data)
|
||||
).toMatchObject([2, 3]);
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "amis-formula",
|
||||
"version": "2.3.1",
|
||||
"version": "2.3.2-beta.1",
|
||||
"description": "负责 amis 里面的表达式实现,内置公式,编辑器等",
|
||||
"main": "lib/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
|
@ -1805,8 +1805,28 @@ export class Evaluator {
|
||||
throw new Error('expected an anonymous function get ' + iterator);
|
||||
}
|
||||
|
||||
return (Array.isArray(value) ? value : []).map((item, index) =>
|
||||
this.callAnonymousFunction(iterator, [item, index])
|
||||
return (Array.isArray(value) ? value : []).map((item, index, arr) =>
|
||||
this.callAnonymousFunction(iterator, [item, index, arr])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据做数据过滤,需要搭配箭头函数一起使用,注意箭头函数只支持单表达式用法。
|
||||
* 将第二个箭头函数返回为 false 的成员过滤掉。
|
||||
*
|
||||
* @param {Array<any>} arr 数组
|
||||
* @param {Function<any>} iterator 箭头函数
|
||||
* @namespace 数组
|
||||
* @example ARRAYFILTER(arr, item => item)
|
||||
* @returns {boolean} 结果
|
||||
*/
|
||||
fnARRAYFILTER(value: any, iterator: any) {
|
||||
if (!iterator || iterator.type !== 'anonymous_function') {
|
||||
throw new Error('expected an anonymous function get ' + iterator);
|
||||
}
|
||||
|
||||
return (Array.isArray(value) ? value : []).filter((item, index, arr) =>
|
||||
this.callAnonymousFunction(iterator, [item, index, arr])
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
"main": "lib/index.js",
|
||||
"module": "esm/index.js",
|
||||
"types": "lib/index.d.ts",
|
||||
"version": "2.3.1",
|
||||
"version": "2.3.2-beta.1",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"build": "npm run clean-dist && NODE_ENV=production rollup -c ",
|
||||
@ -33,8 +33,8 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"amis-core": "^2.3.1",
|
||||
"amis-formula": "^2.3.1",
|
||||
"amis-core": "^2.3.2-beta.1",
|
||||
"amis-formula": "^2.3.2-beta.1",
|
||||
"classnames": "2.3.1",
|
||||
"codemirror": "^5.63.0",
|
||||
"downshift": "6.1.12",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "amis",
|
||||
"version": "2.3.1",
|
||||
"version": "2.3.2-beta.1",
|
||||
"description": "一种MIS页面生成工具",
|
||||
"main": "lib/index.js",
|
||||
"module": "esm/index.js",
|
||||
@ -40,8 +40,8 @@
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"amis-core": "^2.3.1",
|
||||
"amis-ui": "^2.3.1",
|
||||
"amis-core": "^2.3.2-beta.1",
|
||||
"amis-ui": "^2.3.2-beta.1",
|
||||
"attr-accept": "2.2.2",
|
||||
"blueimp-canvastoblob": "2.1.0",
|
||||
"classnames": "2.3.1",
|
||||
|
7
revision.json
Normal file
7
revision.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"branch": "master",
|
||||
"SHA1": "67f839d18",
|
||||
"message": "docs: 处理移动端HTML报错 (#5536)",
|
||||
"author": "RUNZE LU",
|
||||
"date": "2022-10-13 11:34:28"
|
||||
}
|
Loading…
Reference in New Issue
Block a user