2015-04-01 35 views
2

我正在研究一段Web開發的代碼,其中有一個頁面正在使用日期範圍和Google Visualization API的數字範圍過濾器。同時,我在整個頁面中使用了AngularJS。

現在,我的問題如下:我有一個表與一定數量的條目。當應用其中一個過濾器時,我希望在HTML頁面的某處顯示條目數(==行數)。

我的意圖來實現,這是通過使用來自谷歌API的getNumberOfRows()方法和結果存儲在一個$scope變量在頁面上使用時,最好將每次範圍過濾器的一個改變狀態時更新。

我已經添加了3個聽衆,一個用於點擊表格行(使用selectHandler()),另一個用於處理範圍過濾器的狀態更改(使用單獨的函數stateChangeHandler())。

我將值存儲在變量$scope.numberOfRowsShown中。

整個事情適用於點擊(selectHandler)。所以,當點擊一個表格行時,我會得到更新的正確的行數,用{{numberOfRowsShown}}(AngularJS)調用HTML頁面上的變量。

做同樣的事情,除了調用函數並將其存儲到變量$scope.numberOfRowsShownstateChangeHandler()內確實給我在控制檯中正確的輸出,但它不會讓我通過調用{{numberOfRowsShown}}再訪問變量。

任何想法?

這裏的JS代碼:

function selectHandler() { 
    // this works!! 
    $scope.numberOfRowsShown = table.getDataTable().getNumberOfRows(); 
}; 

function stateChangeHandler() { 
    // this does not work.. 
    $scope.numberOfRowsShown = table.getDataTable().getNumberOfRows(); 
    // correct output in the console.. 
    console.log(table.getDataTable().getNumberOfRows()); 
}; 

// Setup listener to listen for clicks on table rows and process the selectHandler. 
google.visualization.events.addListener(table, 'select', selectHandler); 

// Setup listeners for statechange in the slider range filters. 
google.visualization.events.addListener(dateOfLastAccessFilter, 'statechange', stateChangeHandler); 
google.visualization.events.addListener(timeSinceLastAccessFilter, 'statechange', stateChangeHandler); 

回答

0

我已經想通了這一點。我需要做的就是重新加載桌子!