为什么JSON列表中只显示第一行

为什么JSON列表中只显示第一行,json,angularjs,asp.net-web-api2,Json,Angularjs,Asp.net Web Api2,我有下表: <div data-ng-app="myApp"> <div data-ng-controller="MyCtrl"> <form> <table> <tr> <td><b>ID</b></td> <td>&

我有下表:

<div data-ng-app="myApp">
    <div data-ng-controller="MyCtrl">
        <form>
            <table>
                <tr>
                    <td><b>ID</b></td>
                    <td><b>Name</b></td>
                    <td><b>Surname</b></td>
                    <td><b>House</b></td>
                    <td><b>Address</b></td>
                    <td><b>Locality</b></td>
                    <td><b>Contact1</b></td>
                    <td><b>Contact2</b></td>
                    <td><b>Contact3</b></td>
                    <td><b>Reply</b></td>
                </tr>
                <tr><td></td></tr>
                <tr ng-repeat="telesale in telesales">
                    <td>{{telesale.ID}}</td>
                    <td>{{telesale.Name}}</td>
                    <td>{{telesale.Surname}}</td>
                    <td>{{telesale.House}}</td>
                    <td>{{telesale.Address}}</td>
                    <td>{{telesale.Locality}}</td>
                    <td>{{telesale.Contact1}}</td>
                    <td>{{telesale.Contact2}}</td>
                    <td>{{telesale.Contact3}}</td>
                    <td>{{telesale.Reply}}</td>
                </tr>
            </table>
        </form>
    </div>
  </div>

身份证件
名称
姓
房子
地址
地点
联系人1
联系人2
联系方式3
回复
{{telesale.ID}
{{telesale.Name}
{{telesale.姓氏}}
{{telesale.House}
{{电话销售.地址}
{{telesale.Locality}
{{telesale.Contact1}}
{{telesale.Contact2}}
{{telesale.Contact3}}
{{电话销售.答复}
控制器:

<script type="text/javascript">
  var myApp = angular.module('myApp', []);

  myApp.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) {

      GetPersons();

      function GetPersons() {
          $http({
              method: 'GET',

              url: '/api/data'
          }).
        success(function (data) {
            if (data != null || data != 'undefined') {
                console.log(data);
                $scope.telesales = data;
            }
        })
      .error(function (error) {
          $window.alert("Unable to retrieve people" + error.message);
      });
      }

  } ]);

var myApp=angular.module('myApp',[]);
控制器('MyCtrl',['$scope','$http',函数($scope,$http){
GetPersons();
函数GetPersons(){
$http({
方法:“GET”,
url:“/api/data”
}).
成功(功能(数据){
if(data!=null | | data!=undefined){
控制台日志(数据);
$scope.telesales=数据;
}
})
.错误(函数(错误){
$window.alert(“无法检索人员”+错误消息);
});
}
} ]);

正在从api控制器检索数据,该控制器返回40个对象的列表,但表中仅显示第一个对象。为什么会发生这种情况

从api检索到的部分数据的屏幕截图(为了隐私而划掉的数据)

看起来第二个(和其他对象)是作为本地传递的,而本地是另一个表的外键

API代码:

public HttpResponseMessage GetPeople()
    {
        List<CommonLayer.Telesales> list = new BusinessLayer.Telesales().getUserSession(User.Identity.Name);
        //List<CommonLayer.Localities> list = new BusinessLayer.Localities().getAllLocalities();
        if (list.Count > 1)
        {
            return new HttpResponseMessage()
            {
                Content = new StringContent(JArray.FromObject(list).ToString(), Encoding.UTF8, "application/json")
            };
        }
        else
        {
            return null;
        }
    }
public HttpResponseMessage GetPeople()
{
List List=new BusinessLayer.Telesales().getUserSession(User.Identity.Name);
//List List=新建BusinessLayer.Localities().getAllLocalities();
如果(list.Count>1)
{
返回新的HttpResponseMessage()
{
Content=newstringcontent(JArray.FromObject(list.ToString(),Encoding.UTF8,“application/json”)
};
}
其他的
{
返回null;
}
}
请看这里 它正在工作,但您应该调整api以获得更好格式的数据

 function GetPersons() {
              $http({
                  method: 'GET',

                  url: 'data.json'
              }).
            success(function (data) {
              console.log(data)
                if (data != null || data != 'undefined') {
                    console.log(data[0].Localities.Telesales);
                    $scope.telesales = data[0].Localities.Telesales;
                }
            })
          .error(function (error) {
              alert("Unable to retrieve people" + error.message);
          });
          }
请看这里 它正在工作,但您应该调整api以获得更好格式的数据

 function GetPersons() {
              $http({
                  method: 'GET',

                  url: 'data.json'
              }).
            success(function (data) {
              console.log(data)
                if (data != null || data != 'undefined') {
                    console.log(data[0].Localities.Telesales);
                    $scope.telesales = data[0].Localities.Telesales;
                }
            })
          .error(function (error) {
              alert("Unable to retrieve people" + error.message);
          });
          }
请看这里 它正在工作,但您应该调整api以获得更好格式的数据

 function GetPersons() {
              $http({
                  method: 'GET',

                  url: 'data.json'
              }).
            success(function (data) {
              console.log(data)
                if (data != null || data != 'undefined') {
                    console.log(data[0].Localities.Telesales);
                    $scope.telesales = data[0].Localities.Telesales;
                }
            })
          .error(function (error) {
              alert("Unable to retrieve people" + error.message);
          });
          }
请看这里 它正在工作,但您应该调整api以获得更好格式的数据

 function GetPersons() {
              $http({
                  method: 'GET',

                  url: 'data.json'
              }).
            success(function (data) {
              console.log(data)
                if (data != null || data != 'undefined') {
                    console.log(data[0].Localities.Telesales);
                    $scope.telesales = data[0].Localities.Telesales;
                }
            })
          .error(function (error) {
              alert("Unable to retrieve people" + error.message);
          });
          }

您的问题是,当您加载
Localities
navigation属性时,您也在加载相关的
Telesales

换句话说,整个
Telesales
表在您加载它的第一个对象时被加载,因为它的导航属性
Localities
,而Localities又加载了与之相关的所有
Telesales
,因此,您可以将整个表
Telesales
加载到导航属性
Localities
中。然后,当web api尝试获取其他
Telesales
对象时,它发现它们都已加载,并将其替换为
$ref:RowId

因此,您需要重新考虑您的查询,这样您就不会加载
Localities
导航属性

免责声明


您可以尝试在一个工具中解析JSON数据,以查看从服务器获得的数据的漂亮表示形式

您的问题是,当您加载
Localities
导航属性时,您也在加载相关的
Telesales

换句话说,整个
Telesales
表在您加载它的第一个对象时被加载,因为它的导航属性
Localities
,而Localities又加载了与之相关的所有
Telesales
,因此,您可以将整个表
Telesales
加载到导航属性
Localities
中。然后,当web api尝试获取其他
Telesales
对象时,它发现它们都已加载,并将其替换为
$ref:RowId

因此,您需要重新考虑您的查询,这样您就不会加载
Localities
导航属性

免责声明


您可以尝试在一个工具中解析JSON数据,以查看从服务器获得的数据的漂亮表示形式

您的问题是,当您加载
Localities
导航属性时,您也在加载相关的
Telesales

换句话说,整个
Telesales
表在您加载它的第一个对象时被加载,因为它的导航属性
Localities
,而Localities又加载了与之相关的所有
Telesales
,因此,您可以将整个表
Telesales
加载到导航属性
Localities
中。然后,当web api尝试获取其他
Telesales
对象时,它发现它们都已加载,并将其替换为
$ref:RowId

因此,您需要重新考虑您的查询,这样您就不会加载
Localities
导航属性

免责声明


您可以尝试在一个工具中解析JSON数据,以查看从服务器获得的数据的漂亮表示形式

您的问题是,当您加载
Localities
导航属性时,您也在加载相关的
Telesales

换句话说