2 回答
TA贡献1796条经验 获得超7个赞
我遇到了类似的问题,请遵循以下步骤:
parseContentResponse(response: any, scope: string, type: string) {
if (response) {
return (
this.getContentObject(
response,
['data', 'Data', `${scope}`, 'content', `${type}`]
)
);
}
return response;
}
//then you could look for the key
private getContentObject(response: any, contentPathArray: Array<string>) {
return contentPathArray.reduce(
(obj, key) => (obj && obj[key] !== 'undefined' ? obj[key] : undefined),
response
);
}
TA贡献1851条经验 获得超5个赞
您可以尝试以下方法:
function findById(o, id) {
//Early return
if( o.id === id ){
return o;
}
var result, p;
for (p in o) {
if( o.hasOwnProperty(p) && typeof o[p] === 'object' ) {
result = findById(o[p], id);
if(result){
return result;
}
}
}
return result;
}
添加回答
举报