【发布时间】:2020-04-19 15:57:59
【问题描述】:
我现在不知道这样做的最佳方法是什么:
我有一个从中您可以选择一种货币的方法,根据您选择的货币,表格会重新呈现为所选货币。
我正在使用来自 mdbreact 的 REACTJS、REDUX 和 MDBDataTable,并且表单正在使用来自 antd 的 Select。
MDBDataTable 正在工作,我可以发送数据,选择也正在工作。我唯一需要的是某种方式来发送我根据这些信息选择货币的信息,我可以构建我的数据发送到我的桌子。
也许这不是正确的想法,我愿意接受任何建议。 (我不是程序员,所以我在寻求帮助)。
我试图将值发送到排序的组件代码(最后):
import React, { Component } from 'react';
import { Select } from 'antd';
import { connect } from "react-redux";
class SelecionarCrypto extends Component {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
this.onBlur = this.onBlur.bind(this);
this.onFocus = this.onFocus.bind(this);
this.onSearch = this.onSearch.bind(this);
console.log("(SelecionarCryto.js):",this.props);
this.state = {
ValorState: "nada"
}
};
onChange(value) {
console.log(`selected ${value}`);
this.setState({ValorState: value});
console.log("(SelecionarCryto.js) New value onchange", this.state.ValorState)
}
onBlur() {
console.log('blur');
}
onFocus() {
console.log('focus');
}
onSearch(val) {
console.log('search:', val);
}
render(){
const { Option } = Select;
console.log("(SelecionarCryto.js) New value Render: ", this.state.ValorState)
return (
<Select
showSearch
style={{ width: 200 }}
placeholder="Seleciona:"
optionFilterProp="children"
onChange={this.onChange}
onFocus={this.onFocus}
onBlur={this.onBlur}
onSearch={this.onSearch}
filterOption={(input, option) =>
option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
>
<Option value="ETH">ETH</Option>
<Option value="BTC">BTC</Option>
<Option value="XRP">XRP</Option>
</Select>
);
}
}
const mapStateToProps = state => {
return {
token: state.token,
};
};
const mapDispatchToProps = (dispatch) =>{
return{
ValorState: "pruebasEnviar"
}
};
export default connect(mapStateToProps, mapDispatchToProps)(SelecionarCrypto);
这部分只是我试图从我的 STORE 中提取价值的部分。
const mapStateToProps = state => {
return {
token: state.token,
ValorState: state.ValorState
};
};
export default connect(mapStateToProps)(PruebasAPI3);
谢谢,
【问题讨论】:
标签: javascript reactjs redux setstate