Skip to content

Instantly share code, notes, and snippets.

@hrdmtr
Last active December 27, 2015 20:39
Show Gist options
  • Save hrdmtr/7386240 to your computer and use it in GitHub Desktop.
Save hrdmtr/7386240 to your computer and use it in GitHub Desktop.
Angular.JS Memo

Tableのフィールドを動的に変更。 http://jsfiddle.net/NkmeG/5/

<div ng-app="myApp" ng-controller="Controller" class="container">
  <table class="table">
    <tr >
      <th ng-repeat="f in meta">
        {{f}}
      </th>
    </tr>
    <tr ng-repeat="record in records ">
      <td ng-repeat="f in meta">
        {{record | fieldFilter:f}}
      </td>
    </tr>
  </table>
</div>
angular.module("myApp", [])
    .filter("fieldFilter", function() {
        return function(input, element) {
            if(element != undefined){
                return input[element];
            }
        };
    });
function Controller($scope) {
    $scope.meta = ["field_2", "field_4"];
    $scope.records = [
      { "field_1" : "value_1_1" ,
        "field_2" : "value_1_2" ,
        "field_3" : "value_1_3" ,
        "field_4" : "value_1_4" ,
        "field_5" : "value_1_5" },
      { "field_1" : "value_2_1" ,
        "field_2" : "value_2_2" ,
        "field_3" : "value_2_3" ,
        "field_4" : "value_2_4" ,
        "field_5" : "value_2_5" },
      { "field_1" : "value_3_1" ,
        "field_2" : "value_3_2" ,
        "field_3" : "value_3_3" ,
        "field_4" : "value_3_4" ,
        "field_5" : "value_3_5" }
    ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment