我正在实施Kurounin Pagination。 我使用全局变量,需要查询具有特定字段的文档。 如何将变量从createContainer发送到global?
(注意:我想将eventId从createContainer发送到const pagination)
(来自console.log(eventId); - >此节目“未定义”)
我的代码如下:
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import createReactClass from 'create-react-class';
import { Link } from 'react-router-dom';
import { Table, Alert, Button, FormGroup, FormControl, Row } from 'react-bootstrap';
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { Events } from '../../api/events';
import { Registers } from '../../api/registers';
import { TotalAmount } from '../../api/registers';
import BootstrapPaginator from 'react-bootstrap-pagination';
import NumberFormat from 'react-number-format';
import Loading from '../../components/Loading';
const pagination = new Meteor.Pagination(Registers, {
filters: {eventid: this.eventId},
sort: {createdAt: 1},
perPage: 10,
reactive: true,
debug: true,
});
console.log(this.eventId);
class DSRegisters extends Component {
render() {
...........
}
DSRegisters.propTypes = {
registers: PropTypes.arrayOf(PropTypes.object).isRequired,
totalCount: PropTypes.number.isRequired,
match: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
evnt: PropTypes.object,
loading: PropTypes.bool.isRequired,
};
export default createContainer(({ match }) => {
eventId = match.params._evntid;
const subevent = Meteor.subscribe('events');
return {
loading: !pagination.ready(),
evnt: Events.findOne(eventId),
registers: pagination.getPage(),
totalCount: Registers.find({ eventid: eventId }).count(),
};
}, DSRegisters);
答案 0 :(得分:0)
我知道了。 我只想添加“regs:pagination.filters({eventid:eventId}),” 按照“registers:pagination.getPage(),” 过滤工作正常。
export default createContainer(({ match }) => {
eventId = match.params._evntid;
const subevent = Meteor.subscribe('events');
return {
loading: !pagination.ready(),
evnt: Events.findOne(eventId),
registers: pagination.getPage(),
regs: pagination.filters({eventid: eventId}),
totalCount: Registers.find({ eventid: eventId }).count(),
};
}, DSRegisters);
以另一种方式删除" regs": 然后添加componentDidMount()
...
componentDidMount() {
subscription.filters({ eventid: this.props.match.params._evntid });
}
...
export default createContainer(({ match }) => {
eventId = match.params._evntid;
const subevent = Meteor.subscribe('events');
return {
loading: !pagination.ready(),
evnt: Events.findOne(eventId),
registers: pagination.getPage(),
totalCount: Registers.find({ eventid: eventId }).count(),
};
}, DSRegisters);