【问题标题】:Insert response data into table将响应数据插入表中
【发布时间】:2017-01-12 17:49:54
【问题描述】:

回应:

    {
    "json": {
      "response": {
        "servicetype": "1",
        "functiontype": "1000",
        "statuscode": "0",
        "statusmessage": "Success",
        "data": [{
            "groupzname": "NARAYANA E-SCHOOL1",
            "groupzcode": "CHATCH",
            "area": "JAYANAGARA 9TH BLOCK",
            "city": "BENGALURU",
            "state": "Karnataka",
            "country": "INDIA"
          },

          {
            "shortname": "School",
            "groupzname": "Smitha School",
            "groupzcode": "4353",
            "area": "fsdfsdf",
            "city": "sdfsf",
            "state": "vxcvxv",
            "country": "vxcvxv"
          }, {
            "shortname": "SerReq",
            "groupzname": "Service R",
            "groupzcode": "SerReq",
            "area": "SerReq",
            "city": "SerReq",
            "state": "SerReq",
            "country": "SerReq"
          }, {
            "shortname": "service",
            "groupzname": "Service Gropz",
            "groupzcode": "1111",
            "area": "jayanagar",
            "city": "bangalore",
            "state": "Karnataka",
            "country": "India"
          }, {
            "shortname": "Testing",
            "groupzname": "Smitha Groupz",
            "groupzcode": "5555",
            "area": "jayanagar 9th block",
            "city": "Bangalore",
            "state": "Karnataka",
            "country": "India"
          },

          {
            "shortname": "May12R2",
            "groupzname": "May12Release2",
            "groupzcode": "May12R2",
            "area": "May12R2Area: ",
            "city": "May12City",
            "state": "May12State",
            "country": "May12Country"
          }, {
            "shortname": "May12",
            "groupzname": "May12Release",
            "groupzcode": "May12",
            "area": "May12 Area",
            "city": "May12 city",
            "state": "May12 State",
            "country": "May12 Country"
          }, {
            "shortname": "Kank",
            "groupzname": "Kankar",
            "groupzcode": "knakr12",
            "area": "Kankar Area",
            "city": "Kankar city",
            "state": "Kankar state",
            "country": "Kankarcountry"
          }, {
            "shortname": "Hir",
            "groupzname": "Heera",
            "groupzcode": "Hir001",
            "area": "Hir are",
            "city": "Hir cit",
            "state": "Hir State",
            "country": "Hir India"
          },

          {
            "shortname": "Apr",
            "groupzname": "Aparajitha",
            "groupzcode": "Apraj20",
            "area": "apar area",
            "city": "apar city",
            "state": "apar state",
            "country": "apar indi"
          }
        ]
      }
    }
  }

我必须将此响应中的上述短名称、组名称、组代码、区域、城市、国家等动态插入到表中。

JS:

     $scope.viewAccount = function(){
                   $scope.showListAccount = true;

              var json = {

  "json": {
    "request": {
      "servicetype": "6",
      "functiontype": "6014",
      "session_id": $rootScope.currentSession,
           "data": {
        "sortbasedon": $scope.groupzname,
        "orderby": "desc",
        "limit":10,
        "offset":10
           }

    }
  }
};

          UserService.viewListAccount(json).then(function(response) {



                 if (response.json.response.statuscode == 0 && response.json.response.statusmessage == 'Success')

                     $scope.dataArray = response.json.response.data;



                        $scope.myname = $scope.dataArray.shortname;
                        console.log($scope.myname);


            }); 
        };

如果我通过上述请求并控制数据,则面临不断增加的错误。 angular.js:68 未捕获的错误:[$rootScope:infdig] 达到 10 个 $digest() 迭代。中止!在最后 5 次迭代中触发的观察者:[]

【问题讨论】:

  • 那么您看到的错误是什么?解析?

标签: angularjs json


【解决方案1】:

由于 Angular 是 MVC 框架,您不必担心视图和模型之间的更新,一切都由控制器自动完成。

【讨论】:

  • 他需要一些指导来完成他要求的工作。虽然有多种解决方案,但如果你指出他正确的方向会更好。我猜你的答案对于新手来说还不够
【解决方案2】:

使用以下代码显示到表格中。

<table>                
    <tr>
        <th>groupzcode</th>
        <th>area</th>
        <th>city</th>
        <th>state</th>
        <th>country</th>
    </tr>
    <tbody>
        <tr data-ng-repeat="data in output.json.response.data">
            <td>{{ data.shortname}}</td>
            <td>{{data.groupzname}}</td>
            <td>{{data.groupzcode}}</td>
            <td>{{data.area}}</td>
            <td>{{data.city}}</td>
            <td>{{data.state}}</td>
            <td>{{data.country}}</td>
        </tr>
    </tbody>
</table>

输出是json输出。

【讨论】:

  • 嗨,我这样做了。但面临不断增加的错误。 angular.js:68 未捕获的错误:[$rootScope:infdig] 达到 10 个 $digest() 迭代。中止!在最后 5 次迭代中触发的观察者:[]
  • 如果您使用了您发布的确切 json 文件,请注意 ,output.json.response.data[0] 不包含 output.json.response.data[0].shortname,
  • 包括它,它应该可以正常工作。而且,对于您的查询,范围变量可以在表中使用,是的,它可以。
  • 我不想在我的 JS 部分做任何事情来做上面的代码。我有点新
  • 用你的范围变量替换'output.json.response.data'。在 js 中写入,$scope.tableData = output.json.response.data 并将上面代码中的 data-ng-repeat="data in output.json.response.data" 替换为 data-ng-repeat="data in tableData" .
【解决方案3】:

在控制器中,

将需要的json数据存入object;

$scope.arrRec = output.json.response.data

这将导致双向数据绑定。每当数据发生变化时,它都会自动反映在视图中。

在视图中,使用ng-repeat指令,

例如用于使用 div。

<div ng-repeat="oneRec in arrRec"  >
 {{oneRec.groupzname}}  {{oneRec.groupzcode}}{{oneRec.area}}
</div>

【讨论】:

  • 您好,表中也可以使用相同的吗?
  • angular.js:68 未捕获的错误:[$rootScope:infdig] 达到 10 $digest() 迭代。中止!在最后 5 次迭代中触发的观察者:[] 我这样做时收到此错误
  • @NicoletaWilskon 请分享生成这个 json 的脚本。探针看起来像那里
猜你喜欢
  • 2012-07-24
  • 1970-01-01
  • 2018-08-30
  • 1970-01-01
  • 2021-02-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-24
相关资源
最近更新 更多