页面编号组件,地图数组查找路径

时间:2017-08-16 14:58:19

标签: javascript reactjs

我正在尝试使用包含路径和id的对象数组创建页码组件。

import React from 'react';

export function PageNumber(props) {

const pageData = [
{path: '/calc/1', id:1},
{path: '/calc/2', id:2},
{path: '/calc/3', id:3},
{path: '/calc/4', id:4},
{path: '/calc/5', id:5},
{path: '/calc/6', id:6},
{path: '/calc/7', id:7}
]

const CurrentPage = props.location.pathname;
const numberOfPages = pageData.length;

如何映射数组并仅显示当前页面?

  return (
      <div>{        
            pageData.map(page => {
                page.path == CurrentPage ? page.path : ''

                <span>{page.path} of {numberOfPages}</span>
            })}  
      </div>
  );
}

0 个答案:

没有答案