SHARE
TWEET

Untitled

a guest Jun 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {"Id":"114","Padre":"CRM","Hijo":"Argumentarios"},
  2. {"Id":"115","Padre":"CRM","Hijo":"Argumentarios"},
  3. {"Id":"116","Padre":"CRM","Hijo":"Argumentarios"},
  4. {"Id":"44","Padre":"Permisos","Hijo":"root"},
  5. {"Id":"45","Padre":"Permisos","Hijo":"root"},
  6. {"Id":"46","Padre":"Permisos","Hijo":"root"},
  7. {"Id":"47","Padre":"Permisos","Hijo":"root"},
  8. {"Id":"50","Padre":"Telefonia","Hijo":"Audio"},
  9. {"Id":"51","Padre":"Telefonia","Hijo":"Audio"},
  10. {"Id":"52","Padre":"Telefonia","Hijo":"Configuracion"},
  11. {"Id":"70","Padre":"Telefonia","Hijo":"Rutas"}]
  12.      
  13. import React, { Component } from 'react';
  14.  
  15. class Nav extends Component{
  16.     constructor(props){
  17.         super(props)
  18.         this.state = {
  19.             menuSubmenu:[]
  20.         }
  21.     }
  22.  
  23.     componentWillMount(){
  24.         fetch('fake_json_menu.php')
  25.         .then(response => response.json())
  26.         .then(menuSubmenu =>{
  27.  
  28.             menuSubmenu.forEach(datos => {
  29.                 let data = {
  30.                     menu:datos.Padre,
  31.                     submenu:datos.Hijo,
  32.                     id:datos.Id
  33.                 }
  34.  
  35.                 //console.log( data )
  36.                 console.log (data.menu);
  37.                 this.setState({
  38.                     menuSubmenu:this.state.menuSubmenu.concat([data])
  39.                 })
  40.             })      
  41.         })
  42.     }
  43.     render(){
  44.         console.log( this.state.menuSubmenu.length )
  45.         if( this.state.menuSubmenu.length > 0 ){
  46.             return(
  47.             <div>
  48.                 { this.state.menuSubmenu.map(datos => <Navegacion key={datos.id} menu={datos.menu} submenu={datos.submenu}/>) }
  49.             </div>
  50.             )
  51.  
  52.         }
  53.         return(
  54.             <p>Cargando usuarios...</p>
  55.         )
  56.     }
  57. }
  58.  
  59. class Navegacion extends Component{
  60.     render(){
  61.         return (
  62.             <li>{this.props.menu}--------{this.props.submenu}</li>
  63.         )
  64.     }
  65. }
  66.  
  67. export default Nav;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top