【问题标题】:Receive data from JSON AngularJS with 2 keys使用 2 个键从 JSON AngularJS 接收数据
【发布时间】:2016-06-14 15:03:36
【问题描述】:

我无法从我从调用的 php 和我的控制器接收到的 JSON 中读取数据,就像这样:

    app.controller('equipoCtrl', ['$scope', '$routeParams', '$http', function($scope,$routeParams,$http){
    $('.mainApp').removeClass('fluid-container').addClass('container');

    $scope.setActive("mClasificacion");
    var idEquipo = $routeParams.idEquipo;
    $scope.actualizado = false;
    $scope.alumno = {};
    $scope.myposition={};
    $scope.posicionSeleccionada="2";
    $scope.posicionSeleccionada2="1";

    $http.get('php/servicios/equipos.getEquipo.php?c='+ idEquipo)
    .success(function(data){

        if (data.err !== undefined) {
            window.location  = "#/equipos";
            return;
        }
        $scope.alumno = data;

    });


    $http.get('php/servicios/alumnos.posiciones.php')
    .success(function(data){

        $scope.myposition=data;
    });




}]);

我的数组名为myposition 的结果如下:

[ { "idPosicion": "2", "posicion": "Delantero" }, { "idPosicion": "1", "posicion": "Portero" } ] 

最后是我的 HTML 代码:

            <div class="col-md-6">
           Posicion Jugador 1:{{posicionSeleccionada}} 
           <select ng-model="posicionSeleccionada" class="form-control" >
              <option ng-repeat="(key,value) in myposition" value=""></option>
           </select>
        </div>

有人可以帮助我,如何检索值?

谢谢,路易吉

【问题讨论】:

  • 当你需要使用数组语法时,你正在使用对象语法
  • 天啊!!!!!!你能告诉我一些例子吗?

标签: javascript angularjs json model-view-controller


【解决方案1】:

当你需要使用数组语法时,你正在使用对象语法

<option ng-repeat="pos in myposition" value="{{pos.idPosicion}}">{{pos.posicion}}</option>

还建议考虑使用ng-options

【讨论】:

  • 研究ng-repeat 文档...示例展示了如何做到这一点
猜你喜欢
  • 2017-02-17
  • 1970-01-01
  • 1970-01-01
  • 2018-03-22
  • 2014-05-26
  • 2018-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多