我正在使用ruby gem:prawn和扩展名prawn-table来为大虾提供创建表的功能。
当您拥有静态数据时,使用对象displayed here创建表的基础知识是直截了当的:
[["0"; "0"]; ["0"; "1"]; ["1"; "0"]; ["1"; "1"]]
[[0; 0]; [0; 1]; [1; 0]; [1; 1]]
大。那不错。但现在我想迭代一个活动的记录关系对象,但我的尝试只是不起作用:
# This works. Easy because it is static data
def prepare_for_print
pdf = Prawn::Document.new
pdf.font_size 11
pdf.font "Times-Roman"
pdf.table([ ["short", "short", "loooooooooooooooooooong "*30],
["short", "loooooooooooooooooooong "*15, "short"],
["loooooooooooooooooooong "*10, "short", "short"] ])
return pdf
end
问题在于迭代相关的调用:
def prepare_for_print
pdf = Prawn::Document.new
pdf.font_size 11
pdf.font "Times-Roman"
calls_by_disability.each do |disability|
pdf.text "#{disability}", style: :bold, color: "001133"
pdf.table([ ["Call ID", "Date", "County", "Service Category", "Service", "Notes"],
disability.calls.each do |call|
["hello", "world", "foo", "bar", "bazz", "adsfsa"],
end
])
end
return pdf
end
任何提示都表示赞赏。谢谢!
答案 0 :(得分:2)
var input = ["that", "thing", "thing", "that", "thing", "that", "thing", "thing", "thing"];
var output = [];
for (var idx = input.indexOf("that", 1); idx !== -1; idx = input.indexOf("that", 1)) {
output.push(input.splice(0, idx));
}
output.push(input);