2017-10-16 40 views
0

我定義了下面抽屜式導航:如何激活鏈接的抽屜式導航

<Drawer 
    id="homepage-drawer" 
    type={Drawer.DrawerTypes.TEMPORARY} 
    visible={visible} 
    position={position} 
    overlay 
    clickableDesktopOverlay={true} 
    onVisibilityToggle={this.handleVisibility} 
    navItems={item} 
    defaultMedia={'desktop'} 
    onClick={this.handleAction.bind(this)} 
    header={(
     <Toolbar 
      nav={isLeft ? null : closeBtn} 
      actions={isLeft ? closeBtn : null} 
      className="md-divider-border md-divider-border--bottom" 
     /> 
    )} 
/> 

以下是我navItems名單:我想,只要我點擊以下

const item = ["About", "Contact Us", "FAQ", "Privacy Policy", "Logout"] 

選項卡,相應的鏈接應該打開,我試圖使用onClick事件做到這一點,但沒有任何事情發生。

回答

0

創建一個字典,如:

const dictionary = { 
    about: { 
     name: "About", 
     link: "/about" 
    }, 
    contact : { 
     name : "Contact Us", 
     link : "/contact_us" 
    }, 
    faq : { 
     name : "FAQ", 
     link : "/faq" 
    }, 
    privacy : { 
     name : "Privacy Policy", 
     link : "/privacy_policy" 
    }, 
    logout : { 
     name : "Logout", 
     link : "/logout" 
    } 
} 

然後在你的陣列和返回循環運行,

<a href = {dictionary.about.link}>{dictionary.about.name}</a>