【发布时间】:2015-10-15 21:33:16
【问题描述】:
我有一个问题。之前没有找到答案,或者这不是我的问题。
我正在构建静态应用程序,我需要在页面上有这样的表格。 (它们只是被绑定在角度......我是新手,我已经卡住了。
<table class="table table-responsive table-striped">
<thead>
<tr>
<th class="text-center"></th>
<th class="text-center">1st</th>
<th class="text-center">2nd</th>
<th class="text-center">3rd</th>
<th class="text-center">4th</th>
<th class="text-center">5th</th>
<th class="text-center">6th</th>
</tr>
</thead>
<tbody>
<tr>
<td>First header</td>
<td class="text-center"><input type="checkbox" ng-model="myModel.myData[1].attribute1" /></td>
<td class="text-center"><input type="checkbox" ng-model="myModel.myData[1].attribute2" /></td>
<td class="text-center"><input type="checkbox" ng-model="myModel.myData[1].attribute3" /></td>
<td class="text-center"><input type="checkbox" ng-model="myModel.myData[2].attribute1" /></td>
<td class="text-center"><input type="checkbox" ng-model="myModel.myData[2].attribute2" /></td>
<td class="text-center"><input type="checkbox" ng-model="myModel.myData[2].attribute3" /></td>
</tr>
而且它更进一步......(即 myModel.myData[3](具有 3 个属性)、myModel.myData[4](具有 3 个属性)、myModel.myData[5](具有 3 个属性))
现在...我必须数数:
- 选择了多少属性1(包括整个 myModel.MyData[1 到 N])
- 选择了多少属性 2(包括整个 myModel.MyData[1 到 N])
- 等等……
我现在得到的所有东西,我都可以通过:{{ myModel.myData[1].attribute1 }} 但它返回给我真/假(这很好) - 但无法在控制器中访问它。 (我的控制器js文件已经差不多清晰了,这里就不放了)
如果 some1 可以帮助我,我可以在哪里搜索解决方案,我将不胜感激。
【问题讨论】:
-
在控制器中,您可以通过循环遍历myModel.myData并检查复选框的状态来创建具有{attributrType, count}的数组。
标签: html angularjs twitter-bootstrap-3