この形式で結果が欲しい
data: [{"label":"present","value":35},
{"label":"absent","value":50},
{"label":"leave","value":45},
{"label":"performance","value":67}]
私はこのコードを試しました
data: <%= @orders.map { |d| {label: d.shipping, value: d.price}}.to_json.html_safe -%>
結果を与える
data: [{"label":"present","value":"35"},
{"label":"absent","value":"50"},
{"label":"leave","value":"45"},
{"label":"performance","value":"67"}]
ここで問題は、存在する最初のラベルにあります。この形式で値「35」を取得しますが、「」なしでのみ値35が必要です。どうすればこれを入手できますか?@orders の私のデータは
[#<Order id: 8, price: "35", purchased_at: "2012-01"
, shipping: "present", created_at: "2012-12-13 08:17:39",
updated_at: "2012-12-13 08:50:13">, #<Order id: 9, price
: "50", purchased_at: "2012-02", shipping: "absent", created_at
: "2012-12-13 08:31:24", updated_at: "2012-12-13 08:50:55">,
#<Order id: 12, price: "45", purchased_at: "2012-03", shipping:
"leave", created_at: "2012-12-13 08:48:37", updated_at: "2012-12-13 08:51:07">
, #<Order id: 13, price: "67", purchased_at: "2012-04", shipping:
"performance", created_at: "2012-12-13 08:48:47", updated_at: "2012-12-13 08:51:18">]