3 回答
TA贡献1874条经验 获得超12个赞
只需稍加努力,您就可以自己找到答案。但是,这里是:
let listOfAuthorities = this.userServices.getAuthorities();
let authorityList = JSON.parse(listOfAuthorities);
authorityList.forEach(authority => {
if(authority.authority === 'ROLE_APEX_SUPPORT') {
// write your logic here
}
});
TA贡献1963条经验 获得超6个赞
当我看到返回的响应中包含 ROLE_APEX_SUPPORT 权限时,我想做点什么
如果我正确理解你的问题,你可能想检查你的数组是否有一个项目 authority: ROLE_APEX_SUPPORT
const input1 = [{
"authority": "ROLE_APEX_SUPPORT"
}, {
"authority": "ROLE_APEX_READONLY"
}];
const input2 = [{
"authority": "ROLE_APEX_READONLY"
}];
function hasAuthority(input, authority) {
return input.some((i) => i.authority === authority);
}
console.log(hasAuthority(input1, "ROLE_APEX_READONLY"))
console.log(hasAuthority(input2, "ROLE_APEX_SUPPORT"))
TA贡献1775条经验 获得超8个赞
要检查您的数据是否包含ROLE_APEX_SUPPORT:
const json = [{"authority":"ROLE_APEX_SUPPORT"}, {"authority":"ROLE_APEX_READONLY"}];
const isROLE_APEX_SUPPORT = json.some(s=>s.authority === 'ROLE_APEX_SUPPORT');
console.log(isROLE_APEX_SUPPORT); // Output: true
要查找您的数据是否包含ROLE_APEX_SUPPORT:
const json = [{"authority":"ROLE_APEX_SUPPORT"}, {"authority":"ROLE_APEX_READONLY"}];
const roleAlexSupport = json.find(s=>s.authority === 'ROLE_APEX_SUPPORT');
console.log(roleAlexSupport ); // OUTPUT: {authority: "ROLE_APEX_SUPPORT"}
此外,您可以使用 json.parse() 方法来解析 JSON:
var json = '{"result":true, "count":42}';
obj = JSON.parse(json);
添加回答
举报