AG-643 Tidy React examples

This commit is contained in:
Sean Landsman
2017-07-25 12:47:07 +01:00
parent a70f248af5
commit 79b0eda61b
6 changed files with 40 additions and 29 deletions

View File

@@ -1,35 +1,34 @@
import React, {Component} from "react";
import ReactDOM from "react-dom";
export default class FloatingFilter extends Component {
constructor(props) {
super();
super(props);
this.state = {
parentModel: null
}
}
onParentModelChanged(parentModel){
this.setState ({
onParentModelChanged(parentModel) {
this.setState({
parentModel: parentModel
})
}
remove(item){
remove(item) {
this.props.onFloatingFilterChanged({
model:this.state.parentModel.filter(it=>it != item)
model: this.state.parentModel.filter(it => it !== item)
});
}
render() {
if (!this.state.parentModel) return null;
let that = this;
let options = this.state.parentModel.map ((item, i)=>{
let that = this;
let removeMeListener = ()=>{
// as the backing filter is a set filter what we're doing here is rendering the list in the set
// and when the [x] removing the selected item, thereby effectively hiding it
let options = this.state.parentModel.map((item, i) => {
let removeMeListener = () => {
this.remove(item)
}
};
let removeMeElement = <a onClick={removeMeListener}>[x]</a>;
return <span key={i}>{item}{removeMeElement}</span>;
});