【发布时间】:2015-10-03 12:38:20
【问题描述】:
我正在尝试像这样注册滚动事件(出现新行时收到通知):
$scope.$on('ngGridEventRows', function (event, rows) {
console.log("Scroll")
});
但它不会触发..(角度 ui-grid 版本:v3.0.6)
实现它的正确方法是什么?
【问题讨论】:
我正在尝试像这样注册滚动事件(出现新行时收到通知):
$scope.$on('ngGridEventRows', function (event, rows) {
console.log("Scroll")
});
但它不会触发..(角度 ui-grid 版本:v3.0.6)
实现它的正确方法是什么?
【问题讨论】:
我不确定他们的原生事件,但您可以为他们的滚动事件创建自己的观察者。
在这个Plunkr 中,我制作了一个滚动播放的观察者。
$scope.gridOptions.onRegisterApi = function(gridApi){
$scope.gridApi = gridApi;
$scope.$watch('gridApi.grid.isScrollingVertically', watchFunc);
function watchFunc(newData) {
if(newData === true) {
$rootScope.$broadcast('scrolled');
}
}
};
还有你的接收者
app.controller('SecondCtrl', ['$scope', function ($scope){
$scope.$on('scrolled', function(event, args) {
console.log('was scrolled');
});
}]);
Plunkr 是根据 their Grid Scrolling 教程创建的。
【讨论】:
如果您想要有关滚动的更准确数据(即实际的滚动事件),您可以改为将网格包装在指令中。我不会在这里包含模板,因为链接配置是关键部分:
angular.module('my-app').directive('myGrid', function($timeout) {
return {
restrict: 'E',
template: "<div><ui-grid></ui-grid></div>",
link: function($scope, $element, $attributes) {
$timeout(function() {
$('div.ui-grid-viewport').on('scroll', function() {
// Your event handling here
});
});
}
};
});
【讨论】:
$scope.$watch("gridApi.grid.isScrollingHorizontally",function(){
//your code
});
【讨论】: