-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
重构代码: yd_array_pickBy函数改为yd_array_pick并重构部分代码
- Loading branch information
Showing
2 changed files
with
17 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
/** | ||
* 从数组中选择指定标签的项 | ||
* @alias yd_array_pickBy | ||
* @alias yd_array_pick | ||
* @category 数组操作 | ||
* @param {object[]} arry - 需要处理的数组,其中每个对象包含 `label` 和 `value` 属性 | ||
* @param {string[]} keys - 需要选择的标签列表 | ||
* @param {Array} arrObj 数组对象 | ||
* @param {string} field 匹配的字段 | ||
* @param {Array} values 匹配的值 | ||
* @returns {object[]} 返回一个新数组,其中只包含具有指定标签的项 | ||
* @author 卞雪瑞 <[email protected]> | ||
* @author 陈随易 <https://chensuiyi.me> | ||
* @summary 这个函数根据给定的标签列表,从数组中选择所有匹配这些标签的项,并返回这些项。 | ||
* @example | ||
* yd_array_pickBy( | ||
* yd_array_pick( | ||
* [{ label: 'a', value: 1 }, { label: 'b', value: 2 }, { label: 'c', value: 3 }], | ||
* 'label', | ||
* ['a', 'c'] | ||
* ); | ||
* 结果: | ||
|
@@ -18,6 +21,6 @@ | |
* { label: 'c', value: 3 } | ||
* ] | ||
*/ | ||
export default (arry, keys) => { | ||
return arry.filter((item) => keys.includes(item.label)); | ||
export default (arrObj, field, values = []) => { | ||
return arrObj.filter((item) => values.includes(item[field])); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters