无法从json响应中获取元素

时间:2017-06-05 16:00:03

标签: javascript angularjs node.js mean-stack

我无法从我的json响应中看到我的表元素,从get方法接收。这是我的HTML:

<div ng-controller="EstadisticaController" data-ng-init="init()">
  <div class="jumbotron text-center">
      <h1>Historico</h1>
      <div class="table-responsive">
        <table class="table table-striped">
          <tr ng-repeat="a in acontecimiento">
            <td>{{ a.campo }}</td>
          </tr>
        </table>
      </div>
  </div>
</div>

控制器:

angular.module('EstadisticaCtrl', ['AcontecimientoService'])
  .controller('EstadisticaController', function($scope, Acontecimiento) {
    $scope.init = function(res) {
      Acontecimiento.get($scope.acontecimiento);
    };
  });

服务:

angular.module('AcontecimientoService', [])
  .factory('Acontecimiento', function($http) {
    return {
        // call to get all nerds
        get : function() {
            return $http.get('/api/acontecimiento');
        }
    }
});

最后是get方法:

var Acontecimiento = require('./models/acontecimiento');
 module.exports = function(app) {
   app.get('/api/acontecimiento', function(req, res) {
       Acontecimiento.find(function(err, acontecimiento) {
           if (err)
               res.send(err);
           res.json(acontecimiento); // return all nerds in JSON format
       });
   });
}

返回的json示例:

[{"_id":"593567528656c9b107d4e6ac","campo":"TRES MARIAS","titular":"RUBEN CARLOS P.","tipo":"CONTAR STOCK ACTUAL","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":12,"fecha":"2017-06-08T03:00:00.000Z"},{"_id":"593567c08656c9b107d4e6af","campo":"TRES MARIAS","titular":"VICTOR HUGO P.","tipo":"TRANSLADO","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":23,"toros":0,"vacas":0,"brucelosis":0,"fecha":"2017-06-15T03:00:00.000Z"},{"_id":"593568c98656c9b107d4e6b0","campo":"TRES MARIAS","titular":"RUBEN CARLOS P.","tipo":"TRANSLADO","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":2,"fecha":"2017-06-08T03:00:00.000Z"},{"_id":"593568f28656c9b107d4e6b1","campo":"GUARANIMINI","titular":"RUBEN CARLOS P.","tipo":"VENTA","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":2,"fecha":"2017-06-03T03:00:00.000Z"},{"_id":"593569348656c9b107d4e6b2","campo":"GUARANIMINI","titular":"RUBEN CARLOS P.","tipo":"MUERTE","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":2,"fecha":"2017-06-03T03:00:00.000Z"},{"_id":"59356adb8656c9b107d4e6b7","campo":"ESPADAÑAL","titular":"VICTOR HUGO P.","tipo":"TRANSLADO","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":12,"brucelosis":0,"fecha":"2017-06-05T03:00:00.000Z"},{"_id":"59356bf98656c9b107d4e6b9","campo":"GUARANIMINI","titular":"RUBEN CARLOS P.","tipo":"VACUNA","__v":0,"terneros":34,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":null,"fecha":"1994-03-12T03:00:00.000Z"},{"_id":"59356c338656c9b107d4e6bb","campo":"GUARANIMINI","titular":"RUBEN CARLOS P.","tipo":"VACUNA","__v":0,"terneros":0,"terneras":0,"vaquillonas":3232,"novillitos":0,"toros":0,"vacas":0,"brucelosis":0,"fecha":"1994-03-12T03:00:00.000Z"},{"_id":"59356fc6f22ca186088a38d7","campo":"GUARANIMINI","titular":"VICTOR HUGO P.","tipo":"VACUNA","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":1,"fecha":"2017-06-05T03:00:00.000Z"},{"_id":"59356ff0f22ca186088a38d9","campo":"TRES MARIAS","titular":"RUBEN CARLOS P.","tipo":"VACUNA","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":0,"fecha":"2017-06-02T03:00:00.000Z"},{"_id":"59357009f22ca186088a38dc","campo":"GUARANIMINI","titular":"RUBEN CARLOS P.","tipo":"VENTA","__v":0,"terneros":0,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":1,"brucelosis":0,"fecha":"2017-06-05T03:00:00.000Z"},{"_id":"593581761587ccdb084f8de5","campo":"TRES MARIAS","titular":"VICTOR HUGO P.","tipo":"MUERTE","__v":0,"terneros":55555,"terneras":0,"vaquillonas":0,"novillitos":0,"toros":0,"vacas":0,"brucelosis":0,"fecha":"2017-06-03T03:00:00.000Z"}]

1 个答案:

答案 0 :(得分:0)

这就是我解决问题的方法,我需要得到响应并将其分配给我的范围。这就是我的新控制器的样子:

def action_cancel(self , cr, uid, ids, context=None):
    return self.write(cr, uid, ids, {'state':'cancel'})