【问题标题】:How to bind Mixed Json to Table in angularjs如何在angularjs中将混合Json绑定到表
【发布时间】:2015-08-13 17:01:04
【问题描述】:
{ "_id" : 1, "name" : { "first" : "John", "last" : "Backus" }, "contribs" : [ "Fortran", "ALGOL", "Backus-Naur Form", "FP" ], "awards" : [            {              "award" : "W.W. McDowell Award",              "year" : 1967,              "by" : "IEEE Computer Society"            },            { "award" : "Draper Prize",              "year" : 1993,              "by" : "National Academy of Engineering"            } ] }

【问题讨论】:

    标签: angularjs json multidimensional-array


    【解决方案1】:

    我已采用您的 JSON 格式并使用 ng-repeat 将其绑定到表中。

    在 html 文件中重复示例:

    <body ng-controller="Ctrl">
    

    <tbody ng-repeat="dat in alldata">
    
      <tr>
        <td colspan="3">{{dat.name.first}} {{dat.name.last}}</td>
    
      </tr>
        <tr><td colspan="3" align="center"><span style="font-weight:bold">Contribution</span></td></tr>
    
      <tr ng-repeat="cont in dat.contribs">
        <td colspan="3">{{ cont}}</td>
    
      </tr>
        <tr><td colspan="3" align="center"><span style="font-weight:bold">Awards</span></td></tr>
        <tr ng-repeat="aw in dat.awards">
        <td>{{ aw.award}}</td>
            <td>{{ aw.year}}</td>
            <td>{{ aw.by}}</td>
    
      </tr>
    
    
    </tbody>
    

    示例脚本文件:

    var app = angular.module("app",[]);
    
    app.controller('Ctrl', function($scope) {
      $scope.alldata = [
       {  
       "_id":1,
       "name":{  
          "first":"John",
          "last":"Backus"
       },
       "contribs":[  
          "Fortran",
          "ALGOL",
          "Backus-Naur Form",
          "FP"
       ],
       "awards":[  
          {  
             "award":"W.W. McDowell Award",
             "year":1967,
             "by":"IEEE Computer Society"
          },
          {  
             "award":"Draper Prize",
             "year":1993,
             "by":"National Academy of Engineering"
          }
       ]
    }
      ];
    });
    

    请找到它的 plnkr 链接:Plnkr

    【讨论】:

    • 能否请您给我表格视图的 hrml 格式,这将有助于我理解您要如何显示它
    猜你喜欢
    • 2013-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 2013-09-30
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    相关资源
    最近更新 更多