我使用django和django石墨烯来生成graphql。
在我的应用程序中,我使用reactJS和反应自举表。React引导表期望我为它传递一个对象数组,但不支持嵌套对象。
我在schema.py中创建了查询
class ApplicationNode(DjangoObjectType):
class Meta:
model = Application
filter_fields = ['name', 'sonarQube_URL']
interfaces = (relay.Node,)
class Query(ObjectType):
application = relay.Node.Field(ApplicationNode)
all_applications = DjangoFilterConnectionField(ApplicationNode)这些查询的答案是JSON嵌套对象,如下所示:
{
"data": {
"allApplications": {
"edges": [
{
"node": {
"id": "QXBwbGljYXRpb25Ob2RlOjE=",
"name": "foo",
"sonarQubeUrl": "foo.com",
"flow":{
"id": "QYBwbGljYXRpb45Ob2RlOjE=",
"name": "flow_foo"
}
}
},
{
"node": {
"id": "QXBwbGljYXRpb25Ob2RlOjI=",
"name": "bar",
"sonarQubeUrl": "bar.com"
"flow":{
"id": "QXBwbGljYXRpb26Ob2RlOjA=",
"name": "flow_bar"
}
}
}
]
}
}
}我得把它们放平,然后再给它们反应
有什么更好的方法,截取石墨烯-django查询的结果,将它们平放,或者在ReactJS视图中执行这个任务?
如果第一种方法更好,如何截取石墨烯-django查询的结果以使其平坦?
发布于 2016-11-08 20:46:00
最好的方法是在一个新组件中封装react引导表。在组件推拿中,继电器道具按反应引导表所需的平面结构。
例如:
MyReactTable = ({allApplications}) => {
let flatApplications = allApplications.edges.map(({node: app}) => {
return {
name: app.name,
sonarQubeUrl: app.sonarQubeUrl,
flowName: app.flow.name
};
});
return (
<BootstrapTable data={flatApplications} striped={true} hover={true}>
<TableHeaderColumn dataField="name" isKey={true} dataAlign="center" dataSort={true}>Name</TableHeaderColumn>
<TableHeaderColumn dataField="sonarQubeUrl" dataSort={true}>Sonar Qube Url</TableHeaderColumn>
<TableHeaderColumn dataField="flowName" dataFormat={priceFormatter}>Flow Name</TableHeaderColumn>
</BootstrapTable>
);
};https://stackoverflow.com/questions/40483094
复制相似问题