0

我正在为我的应用程序创建一个 API。为了创建我的 API,我使用 RABL,并且我计划将我的 API 数据用于JS Flot Charts。Flot的输入结构如下:

{
        "label":"Total Orders",
        "dataBar":[
            [
                1325376000000,
                45023
            ],
            [
               1325462400000,
                23090
            ],
            [
                1325548800000,
                49002
            ],
            [
                1325635200000 ,
                32909
            ],
            [
                1325721600000,
                80211
            ]
        ]
    }

但是 RABL 输出以下 JSON:

[{"order":{"total":"120.0","store_id":244234563,"completed_at":1358432510000}},{"order":{"total":"120.0","store_id":244234563,"completed_at":1358432513000}},{"order":{"total":"120.0","store_id":244234563,"completed_at":1358432515000}}]

我应该如何修改 RABL 的结构以便在 Flot 中使用它?

谢谢。

4

1 回答 1

2

我对 RABL 一无所知,但它是 javascript 方面的 jquery 单行代码:

var data = [{"order":{"total":"120.0","store_id":244234563,"completed_at":1358432510000}},{"order":{"total":"120.0","store_id":244234563,"completed_at":1358432513000}},{"order":{"total":"120.0","store_id":244234563,"completed_at":1358432515000}}]
var flotData = $.map(data, function(i){ return [[i.order.completed_at, parseInt(i.order.total)]] });
于 2013-01-29T17:25:40.387 回答