javascript - 动态检查 json 属性
问题描述
如何将 propertyName 正确传递给 isValid() 函数,以便我能够检查它是否不为空?当我直接检查“searchInside.attendeeList”时,它可以工作!
function isValid(searchInside, propertyName) {
if(searchInside.propertyName)
console.log("this doesnt work");
if(searchInside.attendeeList)
console.log("this works");
}
var requestBody = {
"meetingType": "Company",
"emailSendingReason": "CREATED",
"attendeeList": [
{
"employeeId": "12345",
"employeeDisplayName": "abc, xyz",
"callInFlag": false,
"infoPackRequiredFlag": true,
"inviteForInfoOnly": true
},
{
"employeeId": "374684678",
"employeeDisplayName": "xyz, poi",
"callInFlag": true,
"infoPackRequiredFlag": true,
"inviteForInfoOnly": false
}
],
"thirdPartyAttendee": {}
};
isValid(requestBody, 'attendeeList');
解决方案
function isValid(searchInside, propertyName) {
if(typeof searchInside[propertyName] !== 'undefined')
console.log("this doesnt work");
if(searchInside.attendeeList)
console.log("this works");
}
推荐阅读
- java - Wiiremock http失败错误
- c# - 无法通过 C# 使用 Selenium 检查复选框控件
- python - 如何使用带有 Flask-AppBuilder 的自定义表单更改选择字段的默认选择?
- authentication - 401.2 出现在本地主机上
- actionscript-3 - 调整窗口大小 AS3
- django - Django ManyToManyField 如何添加 created_at 和 updated_at
- java - 如何单击 href="javascript:void(0)" 链接并将路径传递给打开的窗口(Selenium)
- c# - Viewmodel 在命名空间中不存在
- android - 为什么 TFS 说我需要接受许可证才能进行 android 构建?
- ios - 多个命令产生错误 xcode 10