问题描述
我只有客户端(本地)Meteor 集合是这样定义的(coffeescript):
I have client side only (local) Meteor collection defined like that (coffeescript):
Products = new Meteor.Collection null
Products = new Meteor.Collection null
但是,当我尝试 find() 提供排序参数时,Meteor 告诉我不支持本地集合的排序.这是可以理解的.
However when I try to find() providing sorting parameters Meteor tells me that sorting of local collections is not supported. This is understandable.
我想知道获得排序结果的最简单/最简单的方法是什么.基本上我总是使用集合中的所有数据,所以保持它处于排序状态可以解决问题.
I would like to know what is the easiest/simplest way to get sorted results. Essentially I always use all the data in the Collection, so keeping it in sorted state would solve the problem.
推荐答案
它对我有用,您使用的是最新版本的 Meteor 吗?在 Meteor Docs 站点上运行此代码:
It works for me, are you using the latest version of Meteor? Running this code works on the Meteor Docs site:
var foos = new Meteor.Collection( null );
for ( var i = 0; i < 100; i++ ) {
foos.insert({ num: i });
}
foos.findOne( {} ).num; // => 0
foos.findOne( {}, { sort: [[ "num", "desc" ]] } ).num; // => 99
这篇关于如何对仅客户端(本地)的 Meteor 集合进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!