index.js
Players Belonging to same zip code:
<input type="text" name="zip_code" defaultValue={zip1} onChange={this.handleChange_zip}></input> <br />
Number of male over certain age: <input type="number" name="age_number" defaultValue= {age1} onChange={this.handleChange_age}></input> <br />
Students not Belonging from a given state:
<select value={state1} onChange={this.handleChange_state}>
<option value="select">Select</option>
<option value="CA">CA</option>
<option value="TX">TX</option>
</select><br/>
List of Subjects received grades: <input type="checkbox" name="subjects" value={check} onChange={this.handleChange_sub}></input><br/>
<button onClick={this.sportsZipSearch.bind(this)}>Submit</button><br />
{zipValue && <Zip result={result} />}
sportsZipSearch = () => {
const { zip1, age1, count } = this.state;
const newArray = students.filter((el) => { return ((el.zip === zip1) && (el.Age <= age1) && (el.sports_state === state1) && check) });
this.setState({ result: newArray, zipValue: true })
}
zip.js
const Zip = (props) => {
return(
props.result.map(
results =>
<h1 key={results.player_first_name}>{results.player_first_name}</h1>
/* This is not a perfect key, but given the values at hand */
)
)
}
答案 0 :(得分:1)
在比较诸如(el.Age <= age1)之类的字符串时要小心。在进行比较之前,应将其解析为int。更改为:
parseInt(el.Age) <= parseInt(age1))
此比较将使您过滤返回[空]。例如:
("15" <= "100")
-> return false