javascript - 我把antdesign的表格引入却报错(可编辑单元格),能不能帮我看一下是为什么
大家讲道理
大家讲道理 2017-04-11 10:07:05
[JavaScript讨论组]

错误:

代码如下:

import { Table, Input, Icon, Button, Popconfirm } from 'antd';

class EditableCell extends React.Component {
  state = {
    value: this.props.value,
    editable: false,
  }
  handleChange = (e) => {
    const value = e.target.value;
    this.setState({ value });
  }
  check = () => {
    this.setState({ editable: false });
    if (this.props.onChange) {
      this.props.onChange(this.state.value);
    }
  }
  edit = () => {
    this.setState({ editable: true });
  }
  render() {
    const { value, editable } = this.state;
    return (

{ editable ?

:

{value || ' '}

}

); } } class EditableTable extends React.Component { constructor(props) { super(props); this.columns = [{ title: 'name', dataIndex: 'name', width: '30%', render: (text, record, index) => ( ), }, { title: 'age', dataIndex: 'age', }, { title: 'address', dataIndex: 'address', }, { title: 'operation', dataIndex: 'operation', render: (text, record, index) => { return ( this.state.dataSource.length > 1 ? ( Delete ) : null ); }, }]; this.state = { dataSource: [{ key: '0', name: 'Edward King 0', age: '32', address: 'London, Park Lane no. 0', }, { key: '1', name: 'Edward King 1', age: '32', address: 'London, Park Lane no. 1', }], count: 2, }; } onCellChange = (index, key) => { return (value) => { const dataSource = [...this.state.dataSource]; dataSource[index][key] = value; this.setState({ dataSource }); }; } onDelete = (index) => { return () => { const dataSource = [...this.state.dataSource]; dataSource.splice(index, 1); this.setState({ dataSource }); }; } handleAdd = () => { const { count, dataSource } = this.state; const newData = { key: count, name: `Edward King ${count}`, age: 32, address: `London, Park Lane no. ${count}`, }; this.setState({ dataSource: [...dataSource, newData], count: count + 1, }); } render() { const { dataSource } = this.state; const columns = this.columns; return (

); } } ReactDOM.render(, mountNode); .editable-cell { position: relative; } .editable-cell-input-wrapper, .editable-cell-text-wrapper { padding-right: 24px; } .editable-cell-text-wrapper { padding: 5px 24px 5px 5px; } .editable-cell-icon, .editable-cell-icon-check { position: absolute; right: 0; width: 20px; cursor: pointer; } .editable-cell-icon { line-height: 18px; display: none; } .editable-cell-icon-check { line-height: 28px; } .editable-cell:hover .editable-cell-icon { display: inline-block; } .editable-cell-icon:hover, .editable-cell-icon-check:hover { color:#2db7f5; } .editable-add-btn { margin-bottom: 8px; }
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(3)
ringa_lee
import { Table, Input, Icon, Button, Popconfirm } from 'antd';

class EditableCell extends React.Component {
    constructor(props) {
        spuer(props);
        
        this.state = {
            value: props.value,
            editable: false,
        }
  }
  handleChange = (e) => {
// ...

state部分在构造函数声明。

高洛峰

你需要 babel-preset-stage-0

伊谢尔伦

编译提示的很清楚,需要把'='改成':'

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号