JS/TS 对象转成JSON string 字符串
过滤其中的部分项
allMenu.value.forEach((_item) => {
console.log(JSON.stringify(_item, ['menuId']))
})
console.log(JSON.stringify(_item, ['menuId', 'menuName']))
一下方法需要进一步核对,没有调试通过
console.log(JSON.stringify(_item,replacer))
function replacer(key: string, value: string) {
elHelper.alertBox('key=' + key)
if (key === 'menuId') {
return value
}
return undefined
}
本文介绍了如何使用JavaScript或TypeScript将对象转换为JSON字符串,并演示了如何通过`replacer`函数过滤掉`menuId`以外的键,以及提到的方法需要进一步调试。
5万+

被折叠的 条评论
为什么被折叠?



