我正在尝试过滤和分页与现代中继和分页容器的连接。这可以正常工作,但是在过滤连接上触发 loadMore() 时不会传输过滤器。
这是我的 React 组件中的提交搜索表单代码,它使用过滤器参数重新获取连接。
_onSubmit = (event) => {
event.preventDefault();
this.props.relay.refetchConnection(
ITEMS_PER_PAGE,
null,
{matching: this.state.search}
);
}
这工作正常,因为容器在重新加载时被过滤。
现在当我加载更多
_loadMore = () => {
const {relay, store} = this.props;
if (!relay.hasMore() || relay.isLoading()) return;
relay.loadMore(
ITEMS_PER_PAGE, // Fetch the next feed items
e => {if (e) console.log(e)},
{matching: this.state.search}
);
}
匹配参数不再有效,我再次获得完整列表。
在分页容器中,我将 getVariables() 设置为包含匹配值,console.log(fragmentVariables.matching) 在这里具有正确的值。
getVariables(props, {count, cursor}, fragmentVariables) {
return {
count,
cursor,
matching: fragmentVariables.matching
};
},
query: graphql.experimental`
query playersStoreQuery(
$count: Int!
$cursor: String
$matching: String
) {
store {
players(
first: $count
after: $cursor
matching: $matching
) @connection(key: "playersStore_players") { ...
但是新连接没有被过滤。
我怀疑问题出在 _loadMore() 调用中,恰好在 relay.loadMore()
或者在@connection 指令中,它应该支持一个过滤器键(我试过过滤器:[$matchstring] 没有运气)。
我怎样才能使这项工作?感谢您抽出时间。