【发布时间】:2020-08-07 14:30:55
【问题描述】:
我是新来的反应。 例如,输入值输入 1,2,3,4 并且在事件 onChange 之后它只需要数字,那么我可以 用退格键删除 4,3,2 而不是 1。在 HTML DOM 中也不能删除 1。
class House extends Component {
state = {
room: null,
};
componentDidMount() {
if (this.props.house.rent) {
this.setState({ rent: this.props.house.rent });
}
}
onChange = (field, value, mutate) => {
if (field === "houseroom") {
value = parseInt(value.replace(/[@,]/g, ""));
}
mutate({
variables: {
},
});
this.setState({
[field]: value,
});
};
render(){
const {house} = this.props;
<SomeInput
type="text"
value={
(house.room&&
`$${house.room.toLocaleString("en")}`) ||
""
}
onChange={e => {
e.target.placeholder = "Room";
this.onChange("houseroom", e.target.value, mutate);
}}
}
/>
}
【问题讨论】:
-
输入标签的值字段是什么?它来自州吗?
-
不,它是对象格式,我无法使用状态。例如 并且如果 value={room} 采用这种格式,那么它适用于其他没有状态的示例。
-
嗨,Vishal,请分享正在呈现输入的组件,以便我们更好地帮助您
-
好的更新了我的问题。谢谢
标签: reactjs react-apollo