以下是网格中Headers
的代码。我想迭代div
类ui-grid-cell-contents
,它位于类ui-grid-header-cell
内,以获取所有列标题&将其保存在数组对象中。
<div class="ui-grid-header-cell clearfix ng-scope ng-isolate-scope ui-grid-coluiGrid-002">
<div class="ng-scope sortable">
<div class="ui-grid-vertical-bar"> </div>
<div class="ui-grid-cell-contents ng-binding" col-index="renderIndex">
Code <span ui-grid-visible="col.sort.direction" ng-class="{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }" class="ui-grid-icon-up-dir"> </span>
</div>
<div class="ui-grid-column-menu-button ng-scope" ng-if="grid.options.enableColumnMenus && !col.isRowHeader && col.colDef.enableColumnMenu !== false" ng-click="toggleMenu($event)"><i class="ui-grid-icon-angle-down"> </i></div>
</div>
</div>
<div class="ui-grid-header-cell clearfix ng-scope ng-isolate-scope ui-grid-coluiGrid-002">
<div class="ng-scope sortable">
<div class="ui-grid-vertical-bar"> </div>
<div class="ui-grid-cell-contents ng-binding" col-index="renderIndex">
EMPLOYEE NAME<span ui-grid-visible="col.sort.direction" ng-class="{ 'ui-grid-icon-up-dir': col.sort.direction == asc, 'ui-grid-icon-down-dir': col.sort.direction == desc, 'ui-grid-icon-blank': !col.sort.direction }" class="ui-grid-icon-up-dir"> </span>
</div>
<div class="ui-grid-column-menu-button ng-scope" ng-if="grid.options.enableColumnMenus && !col.isRowHeader && col.colDef.enableColumnMenu !== false" ng-click="toggleMenu($event)"><i class="ui-grid-icon-angle-down"> </i></div>
</div>
</div>
.......
我试过了: -
jq(".ui-grid-header-cell > .ui-grid-cell-contents").each(function (index, element) {
console.log(element);
});
不会给出预期的结果。
答案 0 :(得分:2)
.ui-grid-cell-contents
元素不是.ui-grid-header-cell
的直接后代,尽管它是一个孩子。只需从选择器中省略>
:
jq(".ui-grid-header-cell .ui-grid-cell-contents").each(function (index, element) {
console.log(element);
});