0

我有这样定义的服务->

storegrServices.factory('productList', ['$resource', function($resource) {
    return $resource('', {},{
        query: {url:'/apis/productshome.php', method:'GET', isArray:false},
        getProductDetail: {url:'/apis/getproductdetail.php', method:'POST', isArray:true}
    });
}]);

在控制器中,这就是我调用 POST 的方式 ->

storegrControllers.controller('productPageCtrl', ['$scope','productList','$routeParams', function($scope, productList, $routeParams) {
    $scope.postVariable = new productList();
    $scope.postVariable.productcode =  $routeParams.code;
    $scope.postVariable.$getProductDetail();
}]);

这会将产品代码发送到服务器,服务器在响应中返回一个数组。我使用过 isArray: true,但它仍然给我一个错误。我的代码中没有“值”变量/对象。

请建议我该如何解决这个问题。

这是我得到的完整错误->

Error: value.push is not a function
resourceFactory/</Resource[name]/promise</<@http://storegr.com/js-lib/angular-resource.js:530
q@http://storegr.com/js-lib/angular.min.js:7
resourceFactory/</Resource[name]/promise<@http://storegr.com/js-lib/angular-resource.js:529
yd/e/k.promise.then/w@http://storegr.com/js-lib/angular.min.js:92
yd/e/k.promise.then/w@http://storegr.com/js-lib/angular.min.js:92
yd/g/<.then/<@http://storegr.com/js-lib/angular.min.js:93
zd/this.$get</h.prototype.$eval@http://storegr.com/js-lib/angular.min.js:101
zd/this.$get</h.prototype.$digest@http://storegr.com/js-lib/angular.min.js:98
zd/this.$get</h.prototype.$apply@http://storegr.com/js-lib/angular.min.js:101
f@http://storegr.com/js-lib/angular.min.js:66
F@http://storegr.com/js-lib/angular.min.js:70
md/</B.onreadystatechange@http://storegr.com/js-lib/angular.min.js:71
http://storegr.com/js-lib/angular.min.js
Line 84

这是来自服务器的响应 ->

[{"sno":21,"cat1":"Beverages","cat1code":"B","cat2":"Carbonated Drinks&Fruit Drinks","cat2code":"CDD","cat3":"Fruit Juices","cat3code":"FJ","cumulative":20,"brand":"Real Juice","product":"Apple","productcode":"B-CDD-FJ-1","imagename":"B-CDD-FJ-1","weight":200,"unit":0,"mrp":20,"margin":0,"wsp":0,"vat":0,"hbprice":0,"discount":0,"availableqty":0,"availableprice":0,"existingqty":0,"existingprice":0,"addedqty":0,"addedprice":0,"soldqty":0,"soldprice":0,"tags":"home"}]
4

1 回答 1

2

我能够解决这个问题,在这里回答它,这样它也可以使其他人受益。

我将我的数组响应修改为这样的 json 对象并且它起作用了。

{ "product":
[{"sno":21,"cat1":"Beverages","cat1code":"B","cat2":"Carbonated Drinks&Fruit Drinks","cat2code":"CDD","cat3":"Fruit Juices","cat3code":"FJ","cumulative":20,"brand":"Real Juice","product":"Apple","productcode":"B-CDD-FJ-1","imagename":"B-CDD-FJ-1","weight":200,"unit":0,"mrp":20,"margin":0,"wsp":0,"vat":0,"hbprice":0,"discount":0,"availableqty":0,"availableprice":0,"existingqty":0,"existingprice":0,"addedqty":0,"addedprice":0,"soldqty":0,"soldprice":0,"tags":"home"}]
}

谢谢你。

于 2014-03-21T20:31:50.167 回答