0

我有 2 个实体如下

person {
  personID,
  personName,
  Array of Cars (Person Car)
}

Cars {
  carID,
  carName
}

然后是 Person-Car 的关系实体,如下所示

PersonCar {
  personID,
  CarID,
  relatedProperty1,
  relatedProperty2
}

现在,为了在 HTML 页面上的数据上表示这一点,我正在执行以下操作

    <div class="row" ng-repeat="person in persons">
       <div class="col-xs-6">
          {{person.personID}} - {{person.personName}}
       </div>
       <div class="col-xs-6">
          <div class="row">
             <div class="col-xs-12" ng-repeat="car in cars">
                {{person.carID}} - {{getCarName(person.carID)}} - 
              {{person.relatedProperty1}} - {{person.relatedProperty2}}
             </div>
             <!-- Each Car-->
          </div>
          <!-- Array of Cars-->
       </div>
       <!-- Array of Cars Section -->
    </div>
    <!-- Person Row-->                      

此外,正在检索数据,如下所示

modelInfo.controller('modelInfoController', function ($scope, $http, $filter) {
    $http.get('http://localhost/person/123').
            success(function(data) {
              $scope.persons = data
            }

            $scope.getCarName = function(carID) {
            $http.get('http://localhost/car/54545').
                    success(function(data) {
                        $scope.persons = data.carName
            }                  
            }

            };

getCarName由于某种未知原因,脚本在函数上无限循环。请帮助我理解这个问题。另外,请让我知道这是否是一个好的 REST 架构。

4

1 回答 1

0

你错过了几个右括号

modelInfo.controller('modelInfoController', function ($scope, $http, $filter) {
    $http.get('http://localhost/person/123').success(
        function(data) {
          $scope.persons = data
        }
    ); // <-- here, closing success function call

    $scope.getCarName = function(carID) {
        $http.get('http://localhost/car/54545').success(
            function(data) {
                $scope.persons = data.carName;
            }
        ); // <-- here too       
    };

}); // <-- and here, closing the controller call

至于 REST,它取决于您的后端服务器端点是如何定义的

尽管在客户端,您可以为您的资源定义服务,即使用 REST 方法(获取、放置、删除、更新)的 $http 包装器

于 2015-01-08T23:34:38.513 回答