好了,答案是很久以前授予,但我仍然認爲,它有一個代碼味道(沒有冒犯海報,但它是次優的。
我所做的是使用網格的ngGridEventData
事件。
您必須小心,因爲它會多次觸發(每行增加一次),但是,因爲我們知道將填充網格的數據的大小,並且由於該事件允許我們檢查多少行已經被渲染,我們可以知道什麼時候最後一行被渲染,這意味着網格沒有被完全顯示(注意:我沒有用滾動網格來測試,有些行可能不可見,有人可以確認是否它在帽子的情況下工作?我個人從不使用滾動網格(它是一個瀏覽器頁面,而不是桌面)。
事情是這樣的:
$scope.$on('ngGridEventData', function (row, event)
{
if (event == $scope.vehicleTypeGridOptions.gridId)
{
console.info('@[email protected] vehicleTypeGridOptions grid updated');
var renderedRows = row['targetScope'].renderedRows.length;
console.info('renderedRows = ' + renderedRows + '; num data rows = ' + $scope.vehicleTypesGridData.length);
if (renderedRows == 0)
{
return;
}
// if grid rowcount = dat length then it's fully displayed
if (renderedRows == $scope.vehicleTypesGridData.length)
{
console.log('vehicleTypeGrid fully rendered. Select row zer0, then populate vehicleDescriptionGrid');
console.info('Select row zer0');
$scope.vehicleTypeGridOptions.selectItem(0, true); // Grid rendered, select first row
// console.table($scope.vehicleTypeGridOptions.selectedItems);
var vehicle_type = $scope.vehicleTypeGridOptions.selectedItems[0].vehicle_type;
console.info(vehicle_type);
}
}
爲什麼要有時間出來嗎?有關它在角度文檔中的任何信息? – Jaanus
我需要把因爲? – Jaanus
糟糕。您需要將它放在$ timeout中,因爲在創建Controller時網格未初始化。另一種方法是制定一項指令。 – user508994