2016-07-30 49 views
0

我試圖將一列UI網格元素複製到一個數組並對它進行排序並比較數組的第一個元素用第一列數據檢查UI網格列數據是否正確排序。量角器 - 將列元素複製到數組中,對它進行排序並將第一個數組元素與第一列數據進行比較

這是我的代碼 -

我得到的錯誤 - unsorted.then不是一個函數。你能幫我麼。也讓我知道如果我可以使用任何其他方法。

在此先感謝。

var rows = element(by.id('grid2')).element(by.css('.ui-grid-render-container-body')).all(by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index')); 
    var results = []; 
     var res = rows.count().then(function(cnt){     
      console.log('inside loop'); 
      console.log(cnt); 
      for(i=0; i < cnt; i++){ 
       ele = test.datacell('grid2',i,0); 
       ele.getText().then(function(txt){ 
       console.log(txt); 
       results.push(txt); 
       }); 
      } 
      var unsorted = results.map(function(element) { 
        console.log(element.getText()); 
        return element.getText(); 
        }); 

      var sorted = unsorted.then(function(texts) { 
       return texts.slice(0).sort(); 
       }); 

      ele = cmn.datacell('grid1',0,colcount); 
      expect(ele.getText()).toEqual(sorted[0]); 
+0

我現在的工作。你能否讓我知道如何按降序排列。謝謝。 –

回答

1

降序排列,你可以嘗試使用這個排序 -

var sorted = unsorted.then(function(texts) { 
    return texts.slice(0).sort(function (a,b) { 
      return b-a; 
    }); 
}); 
+0

謝謝。我發現reverse()是按降序排序的函數。 –

相關問題