0

我有以下代码:

sql = "select Board_Name AS 'Board Name', COUNT(Board_Name) AS 'Count' from dbo.TABLE  GROUP BY Board_Name"
result = client.execute(sql)
result.each do |row|
  binfo = [ label: row['Board Name'], value: row['Count'] ]
  send_event('ticketsbyboard', { items: binfo })
end

我试图将所有传递给 send_event 的行作为一个数组,而不是一次只有一行。

4

1 回答 1

0

试试地图:

binfo = result.map do |row|
  { label: row['Board Name'], value: row['Count'] }
end
send_event('ticketsbyboard', { items: binfo })

如果您的result对象不直接响应map,只需使用result.to_a.map

于 2013-03-31T19:00:01.703 回答