I am trying to do a search functionality for my app, this is my first React app and don't see the advantages yet
here I have this code
let falsyData = [
{'hello': 'greet'},
{'Travel': 'traveling'},
{'Heart': 'corazon'},
{'Earth': 'tierra'},
{'Hills': 'a name'},
{'Blackjack': 'game'},
{'Casino': 'gambling'}
];
class UniversalSearch extends Component {
constructor() {
super();
this.state = {value : '', result: ''};
}
render () {
let searchRes = this._matchPeople(this.state.value),
match = searchRes.map(function(item) {
return <Column><Paper>{item}</Paper></Column>;
});
return (
<Grid>
<Row>
<Column>
<TextField onChange={this._onChange.bind(this)}
onKeyUp={this._changeInput.bind(this)} value={this.state.value} />
{!!this.state.value.length &&
<Row>
{match}
</Row>
}
</Column>
</Row>
</Grid>
);
}
_matchPeople = (input) => {
let reg = new RegExp(input.split('').join('\\w*').replace(/\W/, ""), 'i');
return falsyData.map(function(person) {
for (let key in person) {
if (key.match(reg)) {
return key;
}
}
});
}
_changeInput = (val) => {
let autoCompleteResult = this._matchPeople(this.state.value);
if (autoCompleteResult.length) {
this.setState({result: autoCompleteResult.join(' ')});
};
}
_onChange = (event) => {
this.setState({value: event.target.value});
}
}
I need to search thru the falsyData
array, so far here are the functions that I am implementing to search
_matchPeople = (input) => {
let reg = new RegExp(input.split('').join('\\w*').replace(/\W/, ""), 'i');
return falsyData.map(function(person) {
for (let key in person) {
if (key.match(reg)) {
return key;
}
}
});
}
_changeInput = (val) => {
let autoCompleteResult = this._matchPeople(this.state.value);
if (autoCompleteResult.length) {
this.setState({result: autoCompleteResult.join(' ')});
};
}
_onChange = (event) => {
this.setState({value: event.target.value});
}
my app is returning the falsyData
criteria I am searching for, but is returning only the attributes and not the properties, so, how should I access to those properties?
for example: If I type hello
, the hello
word should be returned from falsyData
and printed to the screen, which is OK, but what about if I want to printo hello
with his properties which is 'greet' as you can see?
And also, I am getting that error:
Warning: Failed propType: Required prop
children
was not specified inRow
. Check the render method ofUniversalSearch
.
I don't know you guys, but I've been with this for the last 3 hours, with Angular it just take | filter:
and that is it.
Thanks in advance if some can help.