Angularjs 在集合中使用 Rowspan
Angularjs using Rowspan in Collections
我有来自JSON请求的数据集合......我想使用角度以行跨度显示......但它尚未正常工作.. 希望你能帮我解决这个问题。
$scope.data = [
{
order_number: "A-0001",
name: "computer 01-01",
status: 'new'
},
{
order_number: "A-0002",
name: "computer 02-01",
status: 'new'
},
{
order_number: "A-0001",
name: "computer 01-02",
status: 'new'
},
{
order_number: "A-0003",
name: "computer 03-01",
status: 'check'
},
{
order_number: "A-0001",
name: "computer 01-03",
status: 'new'
},
{
order_number: "A-0003",
name: "computer 03-02",
status: 'check'
}
];
我希望我的收藏显示在这样的表格中。
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order Number</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3">A-0001</td>
<td>01-01</td>
<td>new</td>
</tr>
<tr>
<td>01-02</td>
<td>new</td>
</tr>
<tr>
<td>01-03</td>
<td>new</td>
</tr>
<tr>
<td>A-0002</td>
<td>02-01</td>
<td>new</td>
</tr>
</tbody>
</table>
演示普伦克
对于真正的角度解决方案,你不需要javascript来改变dom。 Angular的目标是让数据本身决定控件的呈现方式。
您是否能够更改数据结构? 我觉得有点奇怪,你的身份证不是唯一的。 我冒昧地更改了它,以便每个订单都有一组sub_orders,其中包括名称和状态。
这是一个数据结构已更改的工作 plunker。http://plnkr.co/edit/lpfAJPejfVGaJqB8f6HR?p=preview
数据结构:
$scope.data = [
{
order_number: "A-0001",
sub_orders: [
{
name: "computer 01-01",
status: "new"
},
{
name: "computer 01-02",
status: "new"
},
{
name: "computer 01-03",
status: "new"
}
]
},
{
order_number: "A-0002",
sub_orders: [
{
name: "computer 02-01",
status: "new"
}
]
},
{
order_number: "A-0003",
sub_orders: [
{
name: "computer 03-01",
status: "new"
},
{
name: "computer 03-02",
status: "new"
}
]
}
];
下面是用于呈现表格的角度代码:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Order Number</th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody ng-repeat="order in data">
<tr>
<td rowspan="{{order.sub_orders.length + 1}}">{{order.order_number}}</td>
</tr>
<tr ng-repeat="suborder in order.sub_orders">
<td>{{suborder.name}}</td>
<td>{{suborder.status}}</td>
</tr>
</tbody>
</table>
只是使用提供的数据为您的问题做出了快速而肮脏的解决方案
http://plnkr.co/edit/fvVh73sXfIRLHw42Q2XM?p=preview
我用ng重复和排序对数据进行了排序
ng-repeat="item in data | orderBy: 'order_number'"
然后使用函数检查我们是否需要行跨度。
对您来说,更好的解决方案是重构数据,就像 MaskedTwilight 的解决方案所建议的那样,以便您的订单已经按订单号分组,并且您的商品是此订单的子集合。你可以减少代码和观察者。
相关文章:
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- Meteor-将选定窗体中的对象添加到集合中
- 主干集合重置和解析
- 使用数据上的角度更改设置集合的第一个元素的动画
- 为集合分配大量的模型弹药
- 如何使用backbone.js从集合中获取模型名称
- Lodash从集合创建集合
- 2个backbone.js集合,具有相同的模型,但排序顺序不同
- 如何合并不同集合的游标并按日期排序
- 将当前用户的 ID 推送到 meteorjs 中集合/文档的内部数组
- 使用它更新集合中的嵌套数组's索引
- 主干-从模板中迭代的集合中获取特定的模型
- 微风得到的是实体而不是对象的集合
- Meteor:插入集合后如何执行JS
- 如何使用javascript var引用Mongo DB集合's字段
- MongoDB-通过比较集合和对象的数组来返回现有字段的数组
- 如何组织用户系统的Mongo集合
- 在Meteor中插入集合时出错
- Meteor:Tracker.autorun/observerChanges&集合未按预期工作
- Angularjs 在集合中使用 Rowspan