清空对象数值
var data = { "user": { "Account": "admin", "Avatar": "1", "RealName": "管理员", "OrganizeName": "长庆油田公司第三采油厂", "OrganizeNames": [], "RoleNames": [{ "Name": "系统管理员", "ID": 4 }, { "Name": "一般人员", "ID": 10 } ], "TaskCount": 5, "TaskBLCount": 5, "BYTaskCount": 0, "BYTaskBLCount": 0 }, "items": [{ "FFPID": "fcd77d54-5112-467b-8333-22528304578b", "OperateUserID": "752896b3-4cc0-48aa-a47e-6e933d6cd354", "OrganizeName": "人事(组织)科", "WFID": "7f96725a-861c-4b2d-98ca-e41ea4fe9f6a", "EntityId": null, "State": 2, "TBeginDate": "/Date(1600272000000)/", "CreateDate": "/Date(1600313974110)/", "ReportName": "提质增效周报表(专项小组)", "ModifyUserName": "管理员", "OperateDate": null, "Enabled": 1, "DeleteMark": 0, "ModifyDate": "/Date(1600314403707)/", "Sign": 0, "IsOpen": 1, "EntityName": null, "ProcessId": "33b3e839-6bb0-406f-bb0f-994f1209bbef", "BeginDate": "/Date(1600313974110)/", "EndDate": null, "ReportId": null, "IsHandle": 0, "CreateUserName": "管理员", "ID": "4714022b-54d8-4557-a35a-a1e588c654a2", "TEndDate": "/Date(1600444800000)/", "CreateUserId": "752896b3-4cc0-48aa-a47e-6e933d6cd354", "OrganizeCode": "0303", "ProcessName": "审核", "Title": "【2020年09月第3周】提质增效周报表(专项小组)", "TaskID": "04fbe4a8-db7c-4f30-ba88-aadf3c28b565" }] }
function deepfn(obj) { for (var k in obj) { var val = obj[k] if (val == undefined || val == undefined) { continue } else if (typeof val === 'string') { obj[k] = '' } else if (Object.prototype.toString.call(val) === '[object Array]') { obj[k] = [] } else if (val instanceof Date) { obj[k] = '' } else if (typeof val == 'object') { deepfn(obj[k]) } else if (typeof val == 'number') { obj[k] = 0 } else if (typeof val == 'boolean') { obj[k] = true } } }