【问题标题】:How can I bind a repeat to a table using an object literal?如何使用对象文字将重复绑定到表?
【发布时间】:2014-08-07 06:29:43
【问题描述】:

我有一个名为 ct.items.columns 的对象......里面有两个字符串,“id”和“name”。

我想绑定角度来构建一个包含两列的动态表..来自我的文字的“id”和“name”。

我试过这个:

<table border ="1">
     <tr class="active">
       <th ng-repeat = "a in ct.items.columns">
    </tr>
</table>

我什么也得不到。我的控制器设置正确..我可以进行其他绑定。在对象 ct.items 我有两个属性.. 列和查询...以及列 0 - id 和 1-name 。

【问题讨论】:

  • 在此处粘贴您的对象。

标签: angularjs binding html-table angularjs-ng-repeat


【解决方案1】:

我不确定你的对象,但你可以像这样制作动态表格。

<div ng-controller="myCtrl">
    <table>
        <tr>
            <th ng-repeat="(heading,val) in ct.items.columns">{{heading}}</th>

        </tr>
        <tr>
            <td ng-repeat="(heading,val) in ct.items.columns">{{val}}</td>
        </tr>
    </table>
</div>

Working Demo

希望这会有所帮助。

【讨论】:

  • 这很好。谢谢。现在我需要将表中的一些值放入我的字段中......并制作其余部分。
【解决方案2】:
   <table border ="1">
      <th>
        <td>id</id>
        <td>name</td>
    </th>
       <tr class="active" ng-repeat ="item in ct.items.columns">
           <th >{{item.id}}</th>
           <th >{{item.name</th>
        </tr>
    </table>

【讨论】:

  • 这很好,我想这个..但我需要自动生成我的字段..重复,我不知道如何显示值。谢谢你的帮助。
猜你喜欢
  • 1970-01-01
  • 2013-12-18
  • 2012-11-11
  • 2011-08-22
  • 1970-01-01
  • 2017-09-17
  • 2012-05-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多