2016-12-05 67 views
0

我有一个包含JSON对象的列表,我想在屏幕上填充在输入栏像NG-模型数据结合的JSON get请求GET请求如下:尝试在获取请求中填充JSON对象的列表?

[{"make":"Mahindra","vin":"1987","model":"XUV","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Nissan","vin":"2039","model":"Terrano","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Toyota","vin":"2456","model":"Camry","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Skoda","vin":"5012","model":"Rapid","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Toyota","vin":"1234","model":"FJ","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Ford","vin":"3401","model":"Ikon","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Tata","vin":"4568","model":"Nano","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]}] 

我writen一个NG重复的名单,但它呈现空白输入域, 脚本看起来像这样的HTML代码一起:

<form> 
    <table id="tableRow" class="table table-bordered tableRow"> 
     <thead> 
     <tr> 
      <th></th> 
      <th><label>Make</label></th> 
      <th><label>Vin</label></th> 
      <th><label>Model</label></th> 
      <th><label>Parts</label></th> 
      <th><label></label></th> 
      <th><label></label></th> 
     </tr> 
     <tr ng-repeat="i in myRow"> 
      <td><button class="btn btn-danger btn-remove" type="button"><i class="glyphicon glyphicon-trash gs"></i></button></td> 
      <td><input type="text" class="form-control" id="makeid" ng-model="myRow[i].make"></td> 
      <td><input type="text" class="form-control" id="vinid" ng-model="myRow[i].vin"></td> 
      <td><input type="text" class="form-control" id="modalid" ng-model="myRow[i].model"></td> 
      <td ng-repeat="part in myRow.item.parts"><input type="text" class="form-control" id="partsid" ng-model="part.name"><input type="text" class="form-control" id="partsid" ng-model="part.desc"></td> 
     </tr> 
     </thead>  
    <tbody id="tableROW"> 
    </tbody> 
    </table> 
    <button type="submit" class="btn btn-primary" ng-click="myRowSub()">Submit</button> 
    <button class="btn btn-warning" ng-click="myGet()">get</button> 
    </form> 

我如何解析JSON对象就像我们在单个对象LIKE myRow做。部分 ???

的GET代码如下:

<script> 
      var app = angular.module('myApp', []); 
      app.controller('myCtrl', function($scope, $http) { 
     $http.get("http://172.17.133.82:8080/restproj/v1/dealer/1234/allcar") 
        .then(function(response) { 
        $scope.myRow = response.data;  
       }); 
        $http.get("http://192.168.11.82:8080/restproj/v1/dealer") 
        .then(function(response) { 
        $scope.myRow = response.data; 

       }); 
</script> 

GET请求范围myRow持有JSON数据。所以我怎样才能访问各个部分在屏幕上呈现它。
哪有我也只交个人记录,而不是发布整个表单数据.....

回答

0

而不是它ng-model="myRow[i].make“应该是ng-model="i.make"

<tr ng-repeat="i in myRow"> 
      <td> 
       <button class="btn btn-danger btn-remove" type="button"><i class="glyphicon glyphicon-trash gs"></i></button> 
      </td> 
      <td> 
       <input type="text" class="form-control" id="makeid" ng-model="i.make"> 
      </td> 
      <td> 
       <input type="text" class="form-control" id="vinid" ng-model="i.vin"> 
      </td> 
      <td> 
       <input type="text" class="form-control" id="modalid" ng-model="i.model"> 
      </td> 
      <td ng-repeat="part in i.parts"> 
       <input type="text" class="form-control" id="partsid" ng-model="part.name"> 
       <input type="text" class="form-control" id="partsid" ng-model="part.desc"> 
      </td> 
      </tr> 

DEMO

+0

但也有其名称和desc的仅一个数据被填充....部分3个模式数据!!我需要在屏幕上显示所有零件的数据 –

0
<tr ng-repeat="rowItem in myRow"> 
    <td><button class="btn btn-danger btn-remove" type="button"><i class="glyphicon glyphicon-trash gs"></i></button></td> 
    <td><input type="text" class="form-control" id="makeid" ng-model="rowItem.make"></td> 
    <td><input type="text" class="form-control" id="vinid" ng-model="rowItem.vin"></td> 
    <td><input type="text" class="form-control" id="modalid" ng-model="rowItem.model"></td> 
    <td ng-repeat="part in rowItem.item.parts"><input type="text" class="form-control" id="partsid" ng-model="part.name"><input type="text" class="form-control" id="partsid" ng-model="part.desc"></td> 
</tr> 

这是否适合您? 您使用的是myRow [i],但我是行项目,所以我将其更改为r owItem在重复。

0

var myApp = angular.module('myApp',[]); 
 

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

 
    $scope.jsonObj = [{"make":"Mahindra","vin":"1987","model":"XUV","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Nissan","vin":"2039","model":"Terrano","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Toyota","vin":"2456","model":"Camry","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Skoda","vin":"5012","model":"Rapid","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Toyota","vin":"1234","model":"FJ","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Ford","vin":"3401","model":"Ikon","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]},{"make":"Tata","vin":"4568","model":"Nano","parts":[{"name":"wheel","desc":"makes it roll"},{"name":"engine","desc":"really shiny"},{"name":"Seats","desc":"leather seat covers"}]}]; 
 
    
 
    
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="MyCtrl"> 
 
    <form> 
 
    <table id="tableRow" class="table table-bordered tableRow"> 
 
     <thead> 
 
     <tr> 
 
      <th></th> 
 
      <th><label>Make</label></th> 
 
      <th><label>Vin</label></th> 
 
      <th><label>Model</label></th> 
 
      <th><label>Parts</label></th> 
 
      <th><label></label></th> 
 
      <th><label></label></th> 
 
     </tr> 
 
     </thead>  
 
    <tbody id="tableROW"> 
 
      <tr ng-repeat="i in jsonObj"> 
 
      <td><button class="btn btn-danger btn-remove" type="button"><i class="glyphicon glyphicon-trash gs"></i></button></td> 
 
      <td><input type="text" class="form-control" id="makeid" ng-model="i.make"></td> 
 
      <td><input type="text" class="form-control" id="vinid" ng-model="i.vin"></td> 
 
      <td><input type="text" class="form-control" id="modalid" ng-model="i.model"></td> 
 
      <td ng-repeat="part in i.parts"><input type="text" class="form-control" id="partsid" ng-model="part.name"><input type="text" class="form-control" id="partsid" ng-model="part.desc"></td> 
 
     </tr> 
 
    </tbody> 
 
    </table> 
 
    </form> 
 
</div>