目前我有一个范围可以按以下标准顺序拉回我的记录:
user=> (constantly (throw (Exception. "but not right now")))
Exception but not right now user/eval8734 (form-init1747541642059004341.clj:1)
user=> (repeatedly (throw (Exception. "but not right now")))
Exception but not right now user/eval8736 (form-init1747541642059004341.clj:1)
并将其转换为如下所示的html块:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
我想要一个像这样布局的html块:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
所以我想我需要按以下顺序拉回记录 - (记录偏移行数)
1 6 11 16
2 7 12
3 8 13
4 9 14
5 10 15
知道在Rails / ActiveRecord中执行此操作的最佳方法是什么?
答案 0 :(得分:1)
您必须知道最终要渲染的列数。我认为这一定对你有用:
columns = 5
MyModel.order(:id).in_groups_of(columns).transpose
你会得到一系列行,每行都有一系列记录。
如果您想要一个独特的数组,可以在最后添加.flatten
。
答案 1 :(得分:0)
使用AR订购无法做到这一点!您必须在控制器或视图中执行此操作。