使分页与React Komposer一起工作
Getting pagination to work with React Komposer
我使用的是Meteor 1.3.4.1、kurounin:pagination 1.0.9和react-komposer 1.8.0 (npm package)。
下面是我在composer函数中实例化分页的代码:function composer(props, onData) {
console.log('loading pages');
const pagination = new Meteor.Pagination(UfcFighters);
if( pagination.ready() ) {
console.log('ready');
const fighters = {
columns: [
{ width: '5%', label: '', className: '' },
{ width: '20%', label: 'Name', className: 'text-center' },
{ width: '20%', label: 'Wins/Losses/Draws', className: 'text-center' },
{ width: '20%', label: 'Weight Class', className: 'text-center' },
{ width: '10%', label: 'Status', className: 'text-center' },
{ width: '10%', label: 'Rank', className: 'text-center' },
],
data: pagination.getPage(),
};
onData(null, { fighters, pagination });
}
};
这是React Komposer的正确用法吗?我注意到分页会不断地加载订阅,并且永远不会准备好显示数据。控制台的输出会反复显示"loading pages",但不会显示"ready"。
看起来很好,我认为你只需要返回如果分页没有准备好。
function composer(props, onData) {
const pagination = new Meteor.Pagination(UfcFighters);
if(!pagination.ready()) { return; }
const fighters = {
columns: [
{ width: '5%', label: '', className: '' },
{ width: '20%', label: 'Name', className: 'text-center' },
{ width: '20%', label: 'Wins/Losses/Draws', className: 'text-center' },
{ width: '20%', label: 'Weight Class', className: 'text-center' },
{ width: '10%', label: 'Status', className: 'text-center' },
{ width: '10%', label: 'Rank', className: 'text-center' },
],
data: pagination.getPage(),
};
onData(null, { fighters, pagination });
};
通过kurounin:pagination的项目维护者得到了答案,这是我更新的代码,确认可以与react komposer一起工作:
const pagination = new Meteor.Pagination(UfcFighters, {
sort: { id: 1 }
});
function composer(props, onData) {
const fighterDocs = pagination.getPage();
if( pagination.ready() ) {
const fighters = {
columns: [
{ width: '5%', label: '', className: '' },
{ width: '20%', label: 'Name', className: 'text-center' },
{ width: '20%', label: 'Wins/Losses/Draws', className: 'text-center' },
{ width: '20%', label: 'Weight Class', className: 'text-center' },
{ width: '10%', label: 'Status', className: 'text-center' },
{ width: '10%', label: 'Rank', className: 'text-center' },
],
data: fighterDocs,
};
onData(null, { fighters, pagination });
}
};
export default composeWithTracker(composer)(FightersList);
我将分页实例移到composer函数之外,因为它不断地实例化新的分页并使应用程序陷入困境。现在它运行得很顺利。
相关文章:
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- document.title函数可以't设置它与php一起工作
- "此网站似乎使用滚动链接定位效果.这可能不能很好地与异步平移一起工作;
- 非常简单的js测试;Don’不要和Minko一起工作
- 无法使我的文本参数与我的查询一起工作
- 为什么Angularjs验证don't与输入[type=“number”]一起工作
- 无法使vash 0.8.0与express 4.12.3一起工作
- 如何使Angular JS控制器与指令一起工作
- 无法使autocompletion与bootstrap和php代码点火器一起工作
- 注入的元素和jQuery脚本.如何让他们一起工作
- 两个独立工作的javascript函数,但不能一起工作
- 角度和砖石一起工作
- Node http-proxy-middleware 不能与本地服务器一起工作
- jQuery脚本不想一起工作
- page.js使examples/hash与hashbang:true一起工作
- javascript使jquery倒计时与UTC时间一起工作
- jQuery.not()选择器无法与类一起工作
- Rails3-可排序列表不能与wysihtml5一起工作
- 替换匹配函数给出了未定义的错误,但它与替换一起工作
- 按钮上的数据加载消息无法与ajax调用一起工作