我正在尝试获取名为 fecha_dia_hoy 和 fecha 的字段,但是,当我这样做时,我总是会得到比赛和数据道具,但是我会如果在调用DiaComoHoyNoticia和News组件后看到请求已正确完成,则无法理解为什么无法获得这些字段。
>>> Article.objects.filter(publications__id=1)
<QuerySet [<Article: Django lets you build Web apps easily>, <Article: NASA uses Python>]>
>>> Article.objects.filter(publications__title__startswith="Science")
<QuerySet [<Article: NASA uses Python>, <Article: NASA uses Python>]>
>>> Article.objects.filter(publications__title__startswith="Science").distinct()
<QuerySet [<Article: NASA uses Python>]>
可能会发生什么?我一直在其他组件中做到这一点,并且它可以工作,但是我不明白为什么这不起作用。谢谢!
编辑:我添加了Post模式:
import { graphql } from 'react-apollo';
import gql from 'graphql-tag';
import React, { Component } from 'react';
import Noticia from '../../views/Noticia';
import DiaComoHoyNoticia from '../DiaComoHoyNoticia';
import PropTypes from 'prop-types';
const query = gql`
query queryPost($id: Int!) {
post(id: $id) {
id
fecha
fecha_dia_hoy
}
}
`;
export class DiaComoHoyWrapper extends Component {
constructor(props) {
// TODO: Realizar la busqnoueda del articulo con Grahpql
// Creador =, contenido, fecha , etc.
super(props);
//this.id = props.data;
}
render() {
this.id = this.props.match.params.id;
const { id } = this.props.match.params.id;
const today = new Date();
const todayDate = today.getDate();
const todayMonth = today.getMonth() + 1;
if (this.props.match.params.categoryId == 28) {
return (
<div>
<DiaComoHoyNoticia dia={todayDate} mes={todayMonth} id={this.id}/>
<Noticia id={this.props.match.params.id} />
</div>
);
} else {
return (
<Noticia id={this.props.match.params.id} />
);
}
}
}
DiaComoHoyWrapper.propTypes = {
data: PropTypes.shape({
loading: PropTypes.bool.isRequired,
currentSortItem: PropTypes.string.isRequired,
error: PropTypes.shape({ message: PropTypes.string }),
}).isRequired,
};
DiaComoHoyWrapper.defaultProps = {};
const queryOptions = {
options: props => ({
variables: {
id: props.match.params.id,
},
}),
};
export default graphql(query, queryOptions)(DiaComoHoyWrapper);