首页 > 代码库 > react常见问题(三)

react常见问题(三)

表格相关

<Table dataSource={data} className="mt1" columns={columns} pagination={pagination}  rowKey={record => record.city_id}/>
const columns = [{
      title: ‘学校名称‘,
      dataIndex: ‘school_name‘,
      key: ‘school_name‘,
      render:(text,record)=>{
        if(text!=null){
          return (<span title={text}>{text.length>15?text.substring(0,15)+‘...‘:text}</span>)
        }
      }
    }]
var page = {
      onChange: (index) => {
        var params={
          pageIndex: index,
          pageSize: 10,
          filter: {
            city_code: this.state.cityCode,
            school_name: this.state.schoolName
        }};
        this.props.dispatch(actions.getlList(params));
      },
      total: parseInt(count),
      showTotal: (total) => {
        return `共 ${count} 条`
      },
      showQuickJumper: false,
      showSizeChanger: false,
    }

表格中的key不允许有空格,dataIndex属性为必须,确保datasource为数组形式

 

react常见问题(三)