如何在使用$ resource时处理包含在回调函数中的api响应?

时间:2017-06-23 09:13:27

标签: javascript angularjs api resources

我正在尝试处理REST Api的响应但无法执行它,因为它在我的angularjs应用程序中使用$ resource包裹回调函数:

服务代码:

apiService.factory("TestQuality", function ($resource) {
    var _url = "http://test.amat.com:8080/TestDashboard/TestQualityServlet";

    return $resource(_url, {}, {

        "query": {
            method: "GET",
            headers: {
                'Content-Type': 'application/json'
            }
        }
    });
});

控制器代码:

..
.

var keyword = $scope.keyword ? $scope.keyword : '';
        var paramsObj = {};

        paramsObj['query'] = keyword;
        paramsObj['callback'] = jsonp_callback;

        $scope.testQualityPromise = TestQuality.query(paramsObj, function(response) {

            if (response && response.data.response.values && response.data.response.values.length > 0) {

                $scope.noData = false;

                $scope.testQualityData = response.data.response.values;

                $scope.testQualityTblData = new NgTableParams(
                {

                }, 
                { counts: [], dataset: $scope.testQualityTblData });

            } else {

                $scope.noData = true;

            }

        });

..

来自REST API的响应:

testqualitycallback({
    "data": {
        "response": [{
            "matches": 1,
            "ngroups": null,
            "values": [{
                "groupValue": "0010-02233",
                "result": [{
                    "afr_total_rejects_qty": 1,
                    "afr_systems_count": 149,
                    "afr_total_shipments_qty": 150.0,
                    "afr_percent": 0.6622516556291391
                }]
            }],
            "name": "test_number"
        }]
    }
})

上面的代码并没有给我理想的反响;需要有关处理此响应的建议,以便将结果集显示在视图中。

0 个答案:

没有答案