0
我想使用哪些值处于Ramda
函数内的“状态”。这将起到类似于“AND”过滤器的作用。所以它可能会收到1个值或几个值。使用Ramda传递阵列与React
如何将数据从组件传递到此ramda函数?
它如何循环'ramda'来添加它们在状态中设置的值?
我把它添加到codepen也:https://codesandbox.io/s/3OGK2pP9
const AndFilter = pipe(
prop('movies'),
filter(
both(
// Example data to show how it should arrive from the react component.
where({ genres: pipe(pluck('name'), contains('foo')) }),
where({ genres: pipe(pluck('name'), contains('bar')) }),
where({ genres: pipe(pluck('name'), contains('baz')) }),
),
),
);
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
movies: dataTest,
selectedFilters: { foo, bar, baz },
};
}
AndFilter =() => {
this.setState({ movies: AndFilter(x) });
};
render() {
return (
<div>
<button onClick={this.AndFilter}>test</button>
{this.state.movies.map(movies => (
<li key={movies.id}> {movies.name} </li>
))}
</div>
);
}
}
你能告诉我一个更全面的例子吗?可能在我的笔上?我试图实现它没有成功。 https://codesandbox.io/s/3OGK2pP9 – Ycon
好一会儿.... –
我还没有跟着。你的例子是针对不同结构化的数据,而'ramda'过滤器也不同。你可以在这里https://codesandbox.io/s/J6WW5BD9l吗?我没有看到变量被传递给'AndFilter'常量。 – Ycon