所以我试图使反应与ES6语法一起工作.在ES5中,我有setInitialState,没有使用函数绑定语法的构造函数.我有一个价格列表是任意的,我希望状态在输入元素改变时改变.但是必须改变合适的价格.
我甚至不确定这是正确的做法.有人可以告诉我这应该做的最新方式吗?
这是我的代码:
import React, {Component} from 'react'
import 'bootstrap/dist/css/bootstrap.css';
export default class PriceTable extends Component {
constructor(props, context) {
super(props, context);
this.state = {
pid: this.props.pid || "12345",
name: this.props.name || "name",
prices: this.props.prices || [
{count: 1, desc: 'one', price: 8.25},
{count: 6, desc: 'six', price: 7.60},
{count: 12, desc: 'twelve', price: 6.953}
]
};
this.setPid = this.setPid.bind(this);
this.setName = this.setName.bind(this);
this.setCount = this.setCount.bind(this, i);
this.setDesc = this.setDesc.bind(this, i);
this.setPrice = this.setPrice.bind(this, i);
this.logDebug = this.logDebug.bind(this);
}
setPid(e) …Run Code Online (Sandbox Code Playgroud)