22 lines
519 B
TypeScript
22 lines
519 B
TypeScript
/**
|
|
* 渲染辅助工具函数
|
|
* 纯函数,无 wx.* 依赖
|
|
*/
|
|
|
|
/**
|
|
* 从对象中提取指定字段,缺失字段填充 null
|
|
* @param item 数据对象
|
|
* @param fieldList 需要的字段名数组
|
|
* @returns 仅包含指定字段的新对象
|
|
*/
|
|
export function getRequiredFields(
|
|
item: Record<string, any>,
|
|
fieldList: string[]
|
|
): Record<string, any> {
|
|
const result: Record<string, any> = {}
|
|
for (const field of fieldList) {
|
|
result[field] = field in item ? item[field] : null
|
|
}
|
|
return result
|
|
}
|