按给定值填充html表字段

时间:2017-01-09 09:11:46

标签: html angularjs

所以这就是我要找的东西。

我收到服务器的回复。 json看起来像这样。

    [
  {
    "id": 2,
    "serial_number": 9011,
    "description": null,
    "number_of_plates": 0,
    "data_directory_id": null,
    "mandrel_id": 53,
    "geometry_id": 3,
    "robot_id": null,
    "stack_type_id": 4,
    "project_id": 1,
    "equipment_status_code_id": 17,
    "process_id": null,
    "dies_id": 2,
    "storage_location_id": null,
    "xray_measurement_id": null,
    "metrology_data_file_id": null,
    "data_representation_id": null,
    "created_by": null,
    "created_at": "2017-01-04 15:22:57",
    "updated_at": "2017-01-04 15:33:20",
    "updated_by": 1,
    "xou_id": null,
    "plates": [
      {
        "id": 51,
        "serial_number": "1234",
        "crc_code": "2",
        "reason": "this is a test",
        "supplier_id": 5001,
        "equipment_status_code_id": 1,
        "plate_type_id": null,
        "coating_id": null,
        "metrology_data_file_id": null,
        "project_id": 8,
        "plate_container_id": null,
        "container_slot_id": null,
        "orientation_id": 21,
        "plate_quality_id": 51,
        "wafer_id": 51,
        "data_representation_id": null,
        "xray_measurement_id": null,
        "process_id": 51,
        "created_by": null,
        "created_at": "2016-12-30 11:45:29",
        "updated_at": "2017-01-09 09:32:22",
        "updated_by": 1,
        "pivot": {
          "stack_id": 2,
          "plate_id": 51,
          "created_at": "2017-01-09 09:32:22",
          "updated_at": "2017-01-09 09:32:22",
          "position": 1
        }
      },
      {
        "id": 52,
        "serial_number": "2214",
        "crc_code": "2",
        "reason": null,
        "supplier_id": 5002,
        "equipment_status_code_id": 1,
        "plate_type_id": null,
        "coating_id": null,
        "metrology_data_file_id": null,
        "project_id": null,
        "plate_container_id": null,
        "container_slot_id": null,
        "orientation_id": 17,
        "plate_quality_id": 51,
        "wafer_id": 51,
        "data_representation_id": null,
        "xray_measurement_id": null,
        "process_id": 51,
        "created_by": null,
        "created_at": "2016-12-30 11:45:29",
        "updated_at": "2017-01-09 09:32:35",
        "updated_by": 1,
        "pivot": {
          "stack_id": 2,
          "plate_id": 52,
          "created_at": "2017-01-09 09:32:35",
          "updated_at": "2017-01-09 09:32:35",
          "position": 1
        }
      }
    ]
  }
]

我想要实现的就是在这样的表格中找到一些东西。

 ---------------------------------
| Stack | Plate        | Position |             
----------------------------------
| 9011  |  1234        |     1
----------------------------------
| 9011  |  2214        |     1
----------------------------------

在html中,这就是我现在所拥有的。

<tbody ng-repeat="item in responseFromServer ">
    <tr>
        <td>{{item.serial_number}}</td>
        <td>
            <span ng-repeat="plate in item.plates">
                {{plate.serial_number}}
                <span ng-if="!$last">,</span>
            </span>
        </td>

        <td>
            <span ng-repeat="p in item.plates">
                <div ng-if="p.pivot.position === null">
                    <span class="badge badge-black">Not set</span>
                </div>
                {{p.pivot.position}}
                <span ng-if="!$last">,</span>
            </span>
        </td>
    </tr>

</tbody>

enter image description here 但这不是我所寻求的。

谢谢你的时间!

2 个答案:

答案 0 :(得分:1)

试试这个!!!

将ng-repeat放在<tr>

<tbody ng-repeat="item in responseFromServer ">
      <tr ng-repeat="plate in item.plates">
        <td>{{item.serial_number}}</td>
        <td>
          <span>
           {{plate.serial_number}}
      </span>
        </td>

&#13;
&#13;
var app = angular.module("app", []);
app.controller("ctrl", function($scope) {
  $scope.responseFromServer = [{
    "id": 2,
    "serial_number": 9011,
    "description": null,
    "number_of_plates": 0,
    "data_directory_id": null,
    "mandrel_id": 53,
    "geometry_id": 3,
    "robot_id": null,
    "stack_type_id": 4,
    "project_id": 1,
    "equipment_status_code_id": 17,
    "process_id": null,
    "dies_id": 2,
    "storage_location_id": null,
    "xray_measurement_id": null,
    "metrology_data_file_id": null,
    "data_representation_id": null,
    "created_by": null,
    "created_at": "2017-01-04 15:22:57",
    "updated_at": "2017-01-04 15:33:20",
    "updated_by": 1,
    "xou_id": null,
    "plates": [{
      "id": 51,
      "serial_number": "1234",
      "crc_code": "2",
      "reason": "this is a test",
      "supplier_id": 5001,
      "equipment_status_code_id": 1,
      "plate_type_id": null,
      "coating_id": null,
      "metrology_data_file_id": null,
      "project_id": 8,
      "plate_container_id": null,
      "container_slot_id": null,
      "orientation_id": 21,
      "plate_quality_id": 51,
      "wafer_id": 51,
      "data_representation_id": null,
      "xray_measurement_id": null,
      "process_id": 51,
      "created_by": null,
      "created_at": "2016-12-30 11:45:29",
      "updated_at": "2017-01-09 09:32:22",
      "updated_by": 1,
      "pivot": {
        "stack_id": 2,
        "plate_id": 51,
        "created_at": "2017-01-09 09:32:22",
        "updated_at": "2017-01-09 09:32:22",
        "position": 1
      }
    }, {
      "id": 52,
      "serial_number": "2214",
      "crc_code": "2",
      "reason": null,
      "supplier_id": 5002,
      "equipment_status_code_id": 1,
      "plate_type_id": null,
      "coating_id": null,
      "metrology_data_file_id": null,
      "project_id": null,
      "plate_container_id": null,
      "container_slot_id": null,
      "orientation_id": 17,
      "plate_quality_id": 51,
      "wafer_id": 51,
      "data_representation_id": null,
      "xray_measurement_id": null,
      "process_id": 51,
      "created_by": null,
      "created_at": "2016-12-30 11:45:29",
      "updated_at": "2017-01-09 09:32:35",
      "updated_by": 1,
      "pivot": {
        "stack_id": 2,
        "plate_id": 52,
        "created_at": "2017-01-09 09:32:35",
        "updated_at": "2017-01-09 09:32:35",
        "position": 1
      }
    }]
  }];
});
&#13;
table, th, td {
   border: 1px solid black;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
  <table>
    <tbody ng-repeat="item in responseFromServer ">
      <tr ng-repeat="plate in item.plates">
        <td>{{item.serial_number}}</td>
        <td>
          <span>
           {{plate.serial_number}}
      </span>
        </td>

        <td>
          <span ng-repeat="p in item.plates">
                        <div ng-if="p.pivot.position === null">
                            <span class="badge badge-black">Not set</span>
</div>
{{p.pivot.position}}
<span ng-if="!$last">,</span>
</span>
</td>
</tr>
</tbody>
</table>
<div ng-app="app" ng-controller="ctrl">
&#13;
&#13;
&#13;

答案 1 :(得分:0)

您是否使用angular.fromJson迁移json? 见这里:https://docs.angularjs.org/api/ng/function/angular.fromJson