AngularJS嵌套手风琴使用ui bootstrap
AngularJS Nested accordian using ui bootstrap
我想在AngularJS中使用UI Bootstrap与父子关系创建一个手风琴。
问题1:父母也可以有n个兄弟姐妹和子女。
Issue 2: Child也可以有n个inner Child。所以它必须深嵌套直到最后一个Child。
问题3:父母也可以没有孩子。
[
{
"bu_id": 8,
"tenant_id": 1,
"company_id": 1,
"bu_name": "Parent 2",
"created_date": "2016-06-26 11:31:07",
"updated_date": "2016-06-26 11:31:07",
"parent_id": null
},{
"bu_id": 9,
"tenant_id": 1,
"company_id": 1,
"bu_name": "Child Of Parent 2",
"created_date": "2016-06-26 11:31:47",
"updated_date": "2016-06-26 11:31:47",
"parent_id": 8
},{
"bu_id": 10,
"tenant_id": 1,
"company_id": 1,
"bu_name": "inner Child Parent 2",
"created_date": "2016-06-26 11:36:30",
"updated_date": "2016-06-26 11:36:30",
"parent_id": 9
},{
"bu_id": 11,
"tenant_id": 1,
"company_id": 1,
"bu_name": "Parent 3",
"created_date": "2016-06-26 11:36:30",
"updated_date": "2016-06-26 11:36:30",
"parent_id": null
}
]
树结构
子节点和父节点在bu_id和parent_id上标识。
我使用ng-repeat-end指令来处理这种情况。标记看起来像这样:
<ul>
<li ng-repeat="item in items">{{item.label}}</li>
<li ng-repeat-end ng-if="item.children">
<ul>
<li ng-repeat="item in item.children">{{item.label}}</li>
</ul>
</li>
</ul>
你可以用模板为'子'项创建一个指令,这样它就会像你的层次结构一样深入:
angular.module.directive('itemRepeater', function() {
return {
template: '<ul>' +
' <li ng-repeat="item in item.children">' +
' {{item.label}}' +
' <li ng-repeat-end ng-if="item.children">' +
' <item-repeater></item-repeater>' +
' </li>' +
' </li>' +
'</ul>';
}
})
:
<ul>
<li ng-repeat="item in items">{{item.label}}</li>
<li ng-repeat-end ng-if="item.children">
<item-repeater></item-repeater>
</li>
</ul>
相关文章:
- angular ui bootstrap:当模式关闭时,promise被解析/拒绝
- 使用 Angular 和 UI-bootstrap 对模态事件绑定无法工作的指令
- angular ui bootstrap typeahead-在附加到body时添加类
- 如何在angularjs-ui-bootstrap中使用模态弹出窗口
- 如何通过不同的方式从控制器加载ui.bootstrap模块
- Angular UI Bootstrap Datepicker动态日期(变量)
- 如何在angular 1.5中将angular component与ui.bootstrap.modal一起使用
- 当使用angular.js和ui.bootstrap时,从模态内部的按钮单击事件未触发
- 赢得价值属性't绑定到ui.bootstrap进度条
- AngularJs的ui.bootstrap问题-崩溃不起作用
- UI Bootstrap for Angular 带有 'collapse' 指令,不调用 expand
- Angular ui.bootstrap.timepicker 落后 1 小时
- angularjs ui.bootstrap.modal service 中的模板和模板 URL 之间的区别
- ui-bootstrap timepicker and ng-model value converter
- AngularJS - Directives with Angular UI Bootstrap
- AngularJS ngModel 在 ui-bootstrap 标签集中不起作用
- 使用 angular-ui-bootstrap 进行弹出窗口
- Angularjs 数据绑定失败,Angular UI-Bootstrap typeahead
- UI Bootstrap Modal 弹出窗口无法在 AngularJS 中正常工作
- 有没有办法在 UI-bootstrap 的轮播组件上配置动画集