let data={
"title": "导出标题",
"contentHeader": "一级目录,二级目录,三级目录,题型,题目,分值,是否简要评议",
"contentList": [
{
"category": "语文1",
"rowNum": 3,
"children": [
{
"category": "规范性",
"rowNum": 2,
"children": [
{
"category": "科学性",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "教学内容正确,无科学性和知识性的错误(0-2,错一处扣1分,扣完为止)",
"score": "2",
"isBrief": "是",
"parentSort": 1,
"secondSort": 1,
"thirdSort": 1
},
{
"category": "规范性",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "文字、符号、单位和公式符合国家标准(0-3,错一处扣1分,扣完为止)",
"score": "3",
"isBrief": "",
"parentSort": 1,
"secondSort": 1,
"thirdSort": 2
}
],
"questionType": "",
"topic": "",
"score": "",
"isBrief": "",
"parentSort": "",
"secondSort": 1,
"thirdSort": ""
},
{
"category": "资源扩展",
"rowNum": 2,
"children": [
{
"category": "资源形式",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "有丰富的和教学内容配合的各种资料、学习辅助材料或网络资源,有利于学生学习(0-5)",
"score": "5",
"isBrief": "",
"parentSort": 1,
"secondSort": 3,
"thirdSort": 1
},
{
"category": "资源引用",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "引用资源来源清楚,确切可信(0-5)",
"score": "5",
"isBrief": "是",
"parentSort": 1,
"secondSort": 3,
"thirdSort": 2
}
],
"questionType": "",
"topic": "",
"score": "",
"isBrief": "",
"parentSort": "",
"secondSort": 3,
"thirdSort": ""
}
],
"questionType": "",
"topic": "",
"score": "",
"isBrief": "",
"parentSort": 1,
"secondSort": "",
"thirdSort": ""
},
{
"category": "写作听力联系",
"rowNum": 3,
"children": [
{
"category": "规范性",
"rowNum": 2,
"children": [
{
"category": "科学性",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "教学内容正确,无科学性和知识性的错误(0-2,错一处扣1分,扣完为止)",
"score": "",
"isBrief": "",
"parentSort": 6,
"secondSort": 1,
"thirdSort": 1
},
{
"category": "规范性",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "文字、符号、单位和公式符合国家标准(0-3,错一处扣1分,扣完为止)",
"score": "",
"isBrief": "",
"parentSort": 6,
"secondSort": 1,
"thirdSort": 2
}
],
"questionType": "",
"topic": "",
"score": "",
"isBrief": "",
"parentSort": "",
"secondSort": 1,
"thirdSort": ""
},
{
"category": "资源扩展",
"rowNum": 2,
"children": [
{
"category": "资源形式",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "有丰富的和教学内容配合的各种资料、学习辅助材料或网络资源,有利于学生学习(0-5)",
"score": "",
"isBrief": "",
"parentSort": 6,
"secondSort": 3,
"thirdSort": 1
},
{
"category": "资源引用",
"rowNum": "",
"children": "",
"questionType": "打分",
"topic": "引用资源来源清楚,确切可信(0-5)",
"score": "",
"isBrief": "",
"parentSort": 6,
"secondSort": 3,
"thirdSort": 2
}
],
"questionType": "",
"topic": "",
"score": "",
"isBrief": "",
"parentSort": "",
"secondSort": 3,
"thirdSort": ""
}
],
"questionType": "",
"topic": "",
"score": "",
"isBrief": "",
"parentSort": 6,
"secondSort": "",
"thirdSort": ""
}
]
}
function removeNull(data, defaultStr = null) {
if (typeof data != 'object' || data == null) {
if ((data == '' || data == "")) {
return defaultStr;
} else {
return data;
}
}
for (const v in data) {
if (data[v] == '' || data[v] == "") {
data[v] = defaultStr;
}
if (typeof data[v] == 'object' || typeof data[v] == 'array' ) {
removeNull(data[v])
}
}
}
removeNull(data)
console.log(data.contentList)
一个对象里的所有空字符串替换成null (递归替换)
最新推荐文章于 2023-10-10 10:07:48 发布