sweet_dashboard_project / jobs / list.rb:47:警告:重复密钥在 第47行忽略:: label sweet_dashboard_project / jobs / list.rb:47: 警告:第47行的重复键忽略:: value sweet_dashboard_project / jobs / list.rb:47:警告:重复密钥在 第47行忽略:: label sweet_dashboard_project / jobs / list.rb:47: 警告:第47行的重复键忽略:: value sweet_dashboard_project / jobs / list.rb:47:警告:重复密钥在 第47行忽略:: label sweet_dashboard_project / jobs / list.rb:47: 警告:第47行的重复键忽略::值
{"a"=>1}
1
{"b"=>2}
2
{"c"=>1}
1
{"d"=>2}
2
{:label=>"d", :value=>"2"}
它只打印最后一个哈希标签(d)和值。同样出现在 仪表板中的列表小部件。你能不能让我知道我怎么做 带来其他标签和价值观?
require "mysql2"
SCHEDULER.every '5s' do
client = Mysql2::Client.new(:host => "10.2.2.1",:username => "abcuser",:database => 'testdb')
po1 = nil
po2 = nil
po3 = nil
po4 = nil
p1=client.query("SELECT count(*) as p1 FROM testdb.tab1 WHERE (p='1')")
p2=client.query("SELECT count(*) as p2 FROM testdb.tab1 WHERE (p='2')")
p3=client.query("SELECT count(*) as p3 FROM testdb.tab1 WHERE (p='3')")
p4=client.query("SELECT count(*) as p4 FROM testdb.tab1 WHERE (p='4')")
p1.each do |i|
puts i # Prints {"a"=>1}
puts i['p1'] #Prints 1
po1 = i['p1']
end
p2.each do |i|
puts i # Prints {"b"=>2}
puts i['p2'] # Prints 2
po2 = i['p2']
end
p3.each do |i|
puts i # Prints {"c"=>1}
puts i['p3'] # Prints 1
po3 = i['p3']
end
p4.each do |i|
#puts i # Prints {"d"=>1}
#puts i['p4'] # Prints 2
po4 = i['p4']
end
po = [ { :label=> "a", :value=> "#{po1}", :label=> "b", :value=> "#{po2}", :label=> "c", :value=> "#{po3}", :label=> "d", :value=> "#{po4}" } ]
send_event('priority', { items: po })
end
答案 0 :(得分:1)
这不是正确的哈希值,因为您重复了密钥:label
和:value
po = [ { :label=> "a", :value=> "#{po1}", :label=> "b", :value=> "#{po2}", :label=> "c", :value=> "#{po3}", :label=> "d", :value=> "#{po4}" } ]
你需要将它重新组织成一个小哈希数组,而不是一个大哈希的数组。
po = [ { :label=> "a", :value=> "#{po1}"}, {:label=> "b", :value=> "#{po2}"}, {:label=> "c", :value=> "#{po3}"}, {:label=> "d", :value=> "#{po4}" } ]