0

我想要这种格式的结果

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">]
4

1 回答 1

1
data: <%= @orders.map { |d| {label: d.shipping, value: d.price.to_i}}.to_json.html_safe -%>
于 2012-12-13T09:46:50.903 回答