小编soh*_*091的帖子

如何使用angular $ http服务从返回的JSON对象获取Odata Next Link

我已经为我的web api实现了Odata查询语法.我成功地只能返回前10个结果和更多结果的链接.但是,我无法从使用angularjs前端的服务器返回的JSON对象中提取此链接.

假设服务器响应如下:

{
  "odata.metadata":"http://localhost:60497/odata/$metadata#tables","value":[
    {
      "id":001,"name":"abc"
    },{
      "id":002,"name":"pqr"
    },{
      "id":003,"name":"xyz"
    },{
      .
      .
      .
  ],"odata.nextLink":"http://localhost:60497/odata/tables?$skip=10"
}
Run Code Online (Sandbox Code Playgroud)

现在我通过使用$ http的成功方法显示数据,方法是将返回的数据分配给变量并使用ng-repeat.我按如下方式分配:

.success(function(data)){
  $scope.foo = data.value;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用以下方法访问下一个链接时:

$scope.link = data.odata.nextLink;
Run Code Online (Sandbox Code Playgroud)

在成功方法中,它给了我一个错误.我在这里错过了什么?我怎样才能访问返回的链接?有没有其他方法来实现服务器端分页?

.net json odata asp.net-web-api angularjs

3
推荐指数
1
解决办法
5693
查看次数

标签 统计

.net ×1

angularjs ×1

asp.net-web-api ×1

json ×1

odata ×1