【发布时间】:2016-03-19 06:18:04
【问题描述】:
嗨,我可以访问容器上 prepareVariables 中的道具吗?
我有一个递归结构:
LocationList = Relay.createContainer(LocationList, {
fragments: {
location: () => Relay.QL`
fragment on LocationPart {
id, children {
id, hasChildren, value,
${LocationListItem.getFragment('location')}
}
}
`
}
});
LocationListItem = Relay.createContainer(LocationListItem, {
initialVariables: {
expanded: false
},
fragments: {
location: (variables) => Relay.QL`
fragment on LocationPart {
id, path, value, description, hasChildren,
${LocationList.getFragment('location').if(variables.expanded)}
}
`
}
});
在根上,我将第一级扩展为:
fragment on LocationPart {
${LocationListItem.getFragment('location', { expanded: true })}
}
我想保留整个状态并在以后恢复它。 我已经涵盖的保留状态,并且我将带有状态的对象树向下传递给所有节点。 所以我希望能够在 prepareVariables 中做到这一点:
prepareVariables() {
return { expanded: this.props.open[this.location.id] };
}
我尝试使用构造函数:
constructor(props) {
super(props);
if (props.open[props.location.id])
props.relay.setVariables({ expanded: true });
}
但随后中继抱怨
提供给 LocationList 的预期道具 location 将由 Relay 获取数据。
这可能吗?
【问题讨论】:
标签: javascript relayjs