循环中的循环来填充数组?

发布于 2024-07-25 09:57:25 字数 346 浏览 5 评论 0原文

我正在构建一个时间注册程序。 用户可以处理一个项目,我想在图表中显示每个用户每个月在一个项目上工作的小时数。 图表插件的工作原理如下:

first_serie = OpenFlashChartLazy::Serie.new(
[["2008-1",100],["2008-2",120],["2008-3",130]],
{:title=>"name_of_user1",:start_date=>Time.mktime(2008,1,1),:items=>8})

这会在图表中添加一条新线。

我的问题是如何循环遍历所有用户并为每个用户填充数据库中的数据的新系列?

I am building a time registration program. Users can work on a project, and I want to display in a chart how many hours each user worked on a project, let's say, each month. The chart plugin works like this:

first_serie = OpenFlashChartLazy::Serie.new(
[["2008-1",100],["2008-2",120],["2008-3",130]],
{:title=>"name_of_user1",:start_date=>Time.mktime(2008,1,1),:items=>8})

This adds a new line in the graph.

My question is how can I loop through all my users and for each fill a new series with data from the database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以酷 2024-08-01 09:57:25

我不知道如何生成 Serie.new 的所有数据,但您可以开始使用它:

@series = []
users = User.find(:all)
users.each do |user|
  @series << OpenFlashChartLazy::Serie.new(blah, blah, blah)
end

这会将所有添加的 Serie 对象添加到数组中。

I have no idea how you generate all the data for Serie.new, but you can get started using this:

@series = []
users = User.find(:all)
users.each do |user|
  @series << OpenFlashChartLazy::Serie.new(blah, blah, blah)
end

This will add all of the added Serie objects to an array.

笑叹一世浮沉 2024-08-01 09:57:25

作为 Pesto 的后续,使用注射会更好。

@series = User.all.inject([]) do |mem, user|
  mem << OpenFlashChartLazy::Serie.new(user.foo, user.bar, user.foobarbob)
end

相同的代码,只是没有 @series = []

As a follow up to Pesto would be nicer to use inject.

@series = User.all.inject([]) do |mem, user|
  mem << OpenFlashChartLazy::Serie.new(user.foo, user.bar, user.foobarbob)
end

Same code, just doesnt have a @series = []

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文