【发布时间】:2018-02-16 18:20:58
【问题描述】:
我正在从事电子商务 React/Redux 项目,我想制作用户可以根据价格过滤器显示产品的功能,我制作了两个输入字段,用户可以在其中输入最小和最大价格值,并且可以显示介于价格范围之间的产品, 该功能正在运行onChange,但不显示范围之间的产品,它显示的是一般产品
谁能帮我解决这个问题,提前谢谢,我的代码和截图附在下面
class PriceInput extends React.Component {
constructor(props) {
super(props);
this.state = {
value: props.values,
};
this.onValueChangeComplete = this.onValueChangeComplete.bind(this);
}
onValueChangeComplete() {
const { onValueChange } = this.props;
onValueChange(this.state.value);
}
render() {
const { currencyCode, limits } = this.props;
const { value } = this.state;
const notChanged = _.isEqual(value, limits);
return (
<div className={styles.wrapper}>
<div className={styles.inputWrapper}>
{I18n.getComponent(
(formattedValue) =>
<input
type="text"
name="min"
className={styles.textInput}
placeholder={formattedValue}
/>,
'filter.price-range-min'
)}
<span className={styles.between}>{I18n.getText('filter.price-aed', {}, 'To')}</span>
{I18n.getComponent(
(formattedValue) =>
<input
type="text"
name="max"
className={styles.textInput}
placeholder={formattedValue}
onChange={this.onValueChangeComplete}
/>,
'filter.price-range-min'
)}
</div>
</div>
);
}
}
我必须在其中使用价格功能的组件
case 'price':
childComponent = (
<PriceInput values={facet.data}
limits={facet.data}
currencyCode={this.props.currency.code}
onValueChange={(data) => this.onSearchChange(facet.code, data)}/>
);
break;
【问题讨论】:
-
有些东西看起来不对劲。也许我误解了一些东西。您的
min输入似乎没有onChange功能。而且您似乎没有在输入中使用this.state.value作为值。props.values是什么样的?它是一个对象吗? -
你能帮我根据你的知识重构代码吗@jonahe
标签: javascript reactjs filter