2014-10-31 68 views
-2

以下是網格中我的Headers的代碼。我想遍歷類ui-grid-header-cell中的divui-grid-cell-contents,以獲取所有列標題&將其保存在Array對象中。Jquery - 在類中獲取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">&nbsp;</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">&nbsp;</span> 
     </div> 
     <div class="ui-grid-column-menu-button ng-scope" ng-if="grid.options.enableColumnMenus &amp;&amp; !col.isRowHeader &amp;&amp; col.colDef.enableColumnMenu !== false" ng-click="toggleMenu($event)"><i class="ui-grid-icon-angle-down">&nbsp;</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">&nbsp;</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">&nbsp;</span> 
     </div> 
     <div class="ui-grid-column-menu-button ng-scope" ng-if="grid.options.enableColumnMenus &amp;&amp; !col.isRowHeader &amp;&amp; col.colDef.enableColumnMenu !== false" ng-click="toggleMenu($event)"><i class="ui-grid-icon-angle-down">&nbsp;</i></div> 
    </div> 
</div> 

....... 

我嘗試這樣做: -

jq(".ui-grid-header-cell > .ui-grid-cell-contents").each(function (index, element) { 
        console.log(element);   
       }); 

不給預期的效果。

+0

我想在陣列中的所有頭名。 – Anup 2014-10-31 09:08:00

回答

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);   
}); 

Here's your jsFiddle

+0

如何獲得div內的文字? – Anup 2014-10-31 09:08:17

+0

@anup'$(element).text();' – Ohgodwhy 2014-10-31 09:08:55