名为navigations.json
的JSON文件:
{
"sidenav.dashboard": "Dashboard",
"sidenav.profile": "Profile",
"sidenav.account": "Account",
}
在JS文件中使用:
import i18n from '../../../i18n'
export const driverItems = [
{
link: '#',
icon: <Edit stroke="#ffffff" />,
text: i18n.t('navigations:sidenav.dashboard'),
open: false
},
{
link: '#',
icon: <Edit stroke="#ffffff" />,
text: i18n.t('navigations:sidenav.profile'),
open: false
},
{
link: '#',
icon: <Edit stroke="#ffffff" />,
text: i18n.t('navigations:sidenav.account'),
open: false
}
]
然后在React组件中循环对象数组:
import { ownerItems, driverItems } from './linksList'
// then looping...
const items = this.state.linksOwnerList.map((item, index) => {
if (Array.isArray(item.submenus)) {
return (
....
结果是 Result
有什么想法吗?