单击父级时,如何仅显示嵌套元素? -反应

时间:2019-06-06 12:35:30

标签: json reactjs

我有一个导航菜单,其中包含使用json创建的三个嵌套级别。当您单击Parent时,它将显示所有子项,而与您按下的父项无关。 我希望您单击Parent仅显示您的孩子,而不显示所有父母的所有孩子……我只需要在Parent和直接{{1 }},它与第三级直接相关并同时显示

我认为,除了条件Child外,我还必须做另一件事来检测父级的来历,但我做不到。另一方面,我认为可以制作.filter或.reduce来仅显示被单击元素的子元素。

this.state.showSubmenu

编辑:我修复了我的代码,现在我的代码可以正常工作了。我可以在菜单中显示三个级别。

"menu":[
{   
    "fsttitle":"CRM", 
    "ico":"auriculares", 
    "fstmenu":[{
            "sndtitle":"Argumentarios",
            "ico":"descargar",      
            "sndmenu":[
                {"Id":"114","trdtitle":"SALUD NORMAL1","URL":"https:/argumentarios\/argsalud.pdf","Closable":"1","Autoload":"0","Visible":"1"},
                {"Id":"115","trdtitle":"SALUD NORMAL2","URL":"https:/argumentarios\/argsalud.pdf","Closable":"1","Autoload":"0","Visible":"1"},
                {"Id":"116","trdtitle":"SALUD NORMAL3","URL":"https:/argumentarios\/argsalud.pdf","Closable":"1","Autoload":"0","Visible":"1"}
            ]
            }]
},
{   "fsttitle":"Permisos", 
    "ico":"candado", 
    "fstmenu":[{
            "sndtitle":"Herramientas",
            "ico":"herramienta",            
            "sndmenu":[
                {"Id":"117","trdtitle":"SALUD NORMAL4","URL":"https:/argumentarios\/argsalud.pdf","Closable":"1","Autoload":"0","Visible":"1"},
                {"Id":"118","trdtitle":"SALUD NORMAL5","URL":"https:/argumentarios\/argsalud.pdf","Closable":"1","Autoload":"0","Visible":"1"},
                {"Id":"120","trdtitle":"SALUD NORMAL7","URL":"https:/argumentarios\/argsalud.pdf","Closable":"1","Autoload":"0","Visible":"1"}
            ]
            },
            {
            "sndtitle":"Leads",
            "ico":"user-lead",      
            "sndmenu":[
                {"Id":"119","trdtitle":"SALUD NORMAL6","URL":"https:/argumentarios\/argsalud.pdf","Closable":"1","Autoload":"0","Visible":"1"}
            ]
            }]
}]

1 个答案:

答案 0 :(得分:0)

您可以在var data = { UserPoolId : _config.cognito.userPoolId, ClientId : _config.cognito.clientId }; var userPool = new AmazonCognitoIdentity.CognitoUserPool(data); var cognitoUser = userPool.getCurrentUser(); window.onload = function(){ if (cognitoUser != null) { cognitoUser.getSession(function(err, session) { if (err) { alert(err); return; } console.log('session validity: ' + session.isValid()); AWS.config.credentials = new AWS.CognitoIdentityCredentials({ IdentityPoolId: _config.cognito.IdentityPoolId }); AWS.config.credentials.get(function(err) { console.log(AWS.config.credentials); // * see above what your response will be console.log(AWS.config.credentials.accessKeyId); console.log(AWS.config.credentials.secretAccessKey); }); } } 函数中使用key参数。 然后,您可以将map传递给index事件处理程序。

onClick