2017-05-16 2 views
0

http応答(JSONレスポンス)をテーブルのhtmlページに表示したいとします。これを達成するために、以下のコントローラ機能を書いた。

$scope.getSensorInfo=function(){         
      var strippeddata = []; 
      $http({ 
       method: "GET", 
       url: "http://xx.xx.xx.xx:4000/config", 
       params: {did: $scope.cid} 
      }).then(function (success) { 
       if (success.data[0] === undefined) { //no device is available with this id 
        $http({ 
         method: "GET", 
         url: "http://xx.xx.xx.xx:4000/info" 
        }).then(function(success1){ 
         $scope.sinfo = success1.data;        
        },function(error1){ 
         console.log('Error ' + JSON.stringify(error1)); 
        }); 
       } else { 
        Object.getOwnPropertyNames(success.data[0].obj).forEach(function (item, idx, list) { 
         Object.defineProperty(strippeddata, idx, { 
          enumerable: true, 
          configurable: true, 
          get: function() { 
           return { 
            name: item, 
            periodicity: success.data[0].obj[item].periodicity,     
           } 
          } 
         }); 
        }); 
        $scope.sinfo = strippeddata; 
       } 
      }, function (error) { 
       console.log('Error ' + JSON.stringify(error)); 
      }); 
    } 

私のHTMLコードは以下の通りです。

<div class="row"> 
      <div class="form-inline form-group"> 
      <div class="col-md-3"> 
       <label for="cnfdeviceid">Device ID</label> 
       <input class="form-control input-md" type="text" id="cnfdeviceid" placeholder="e.g. HYD01" ng-model="confdeviceid" ng-blur="getSensorInfo()"/> 
      </div> 
      </div> 
</div> 



<div ng-repeat="y in sinfo" class="[ form-group form-inline ]"> 
      <input class="form-control input-md" type="checkbox" id="{{y.name}}" ng-model="name" ng-change="verify(y.name,y.periodicity,y.formula,name,$index)" autocomplete="off"/> 
      <div class="[ btn-group ]"> 
      <label for="{{y.name}}" class="[ btn btn-success ]"> 
      <span class="[ glyphicon glyphicon-ok ]"></span> 
      <span> </span> 
      </label> 
      <label for="{{y.name}}" class="[ btn btn-default active ]"> 
       {{y.name}} 
      </label> 
      </div> 
      <input class="form-control input-md" type="text" ng-model="y.periodicity" placeholder="periodicity" id="{{y.periodicity}}" autocomplete="off"/> 
    </div> 

私はこのコードを実行しているときに、$ digest 10回の繰り返しでエラーが発生しました。次の行は問題を引き起こしていますが、私はそれを修正することができません。

$scope.sinfo = strippeddata; 

答えて

0

Changing $ scope.sinfo = strippeddata; 〜$ scope.sinfo = strippeddata.slice();問題を解決しました。

関連する問題