Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem in the handler function #9

Open
peel70 opened this issue Dec 11, 2015 · 4 comments
Open

Problem in the handler function #9

peel70 opened this issue Dec 11, 2015 · 4 comments

Comments

@peel70
Copy link

peel70 commented Dec 11, 2015

Hi, I think there is a problem in the handler function.
After the first time the scroll go to the end and is fired the event to load data, the handler function does not update the rows and the lastChoice variable so for every scroll is fired the event to load data.
Maybe I don't understand very well to use the extension.
Please let me know.
Best regards
Enrico

@peel70
Copy link
Author

peel70 commented Dec 12, 2015

I temporary put this two lines in the handler function, I know this is not optimized but it work

var handler = function() {
var rows = elem.querySelectorAll('.ui-select-choices-row');
var lastChoice = angular.element(rows[rows.length - 1]);

.........

every time the handler function is called (for every scroll event) I recalculate the lastChoise

@peel70
Copy link
Author

peel70 commented Dec 12, 2015

Hi, I found another solution but I need your opinion.
I put a watcher on the $select.items array and only when the select is opened I assign a local boolean variable that tell to handler function to recalculate the last element.
I put this watcher in the link function of the directive

var itemsWatcher = scope.$watch('$select.items', function(newItems, oldItems) {
if(scope.$select.open == true) {
needLastChoiceUpdate = true;
}
}, true);

in the handler function I put this code:

var handler = function() {
if(needLastChoiceUpdate == true) {
var rows = elem.querySelectorAll('.ui-select-choices-row');
var newLastChoice = angular.element(rows[rows.length - 1]);
if( newLastChoice != lastChoice ) needLastChoiceUpdate = false;
lastChoice = newLastChoice;
}
//... rest of the function

because the function that will download the new items is async I make another check if the newLastChoice is different from the previous so at the next scroll event I decided to evaluate the last choice again.

The itemsWatcher has to be destroyed in the

scope.$on('$destroy', function() {
// .....
itemsWatcher();
});

Please let me know
Best regards
Enrico

@zukilover
Copy link

is this still being maintained?

@hyzhak
Copy link
Owner

hyzhak commented Sep 22, 2016

@zukilover sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants