Skip to content

Commit

Permalink
* common-list: add getItems option to common list.
Browse files Browse the repository at this point in the history
  • Loading branch information
catouse committed Aug 27, 2024
1 parent 84aa7c8 commit 5198417
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/common-list/src/component/common-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ export class CommonList<P extends CommonListProps = CommonListProps, S = {}> ext
} else if (!Array.isArray(items)) {
items = [];
}
const {getItems} = props;
if (getItems) {
const result = getItems.call(this, items as Item[]);
if (result !== undefined) {
return result;
}
}
return items as Item[];
}

Expand Down
8 changes: 8 additions & 0 deletions lib/common-list/src/types/common-list-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export interface CommonListProps<T extends Item = Item> extends HElementProps {
*/
getItem?: (item: T, index: number) => T | false | undefined;

/**
* Get items, can convert original items.
*
* @param items - The list items.
* @returns The modified list items.
*/
getItems?: (items: Item[]) => Item[] | undefined;

/**
* Item render functions.
*/
Expand Down

0 comments on commit 5198417

Please sign in to comment.