Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
.listview('refresh') iterates over entire list? #6680
I'm finding container.listview('refresh') does work over the entire list rather than just new (i.e. appended) items?
In my use case I'm regularly appending (via ajax) a small number (5) of items. In order to style the new items, the documentation advises me to call listview('refresh'). This starts fast, and then becomes exponentially slower.
Once my list reaches a length of 200 items, on my fastest testing device (Nexus 7), I'm waiting ~7 seconds for listview('refresh') to complete, during which my list is unusable, on my slowest device, I'm waiting >10 seconds.
Is this normal behaviour? I can see the use case for needing to check for changes to items, but in my case items never change, and all this work taking place every time the list is appended is obviously a complete waste of resources and renders the list unusable.
If it is normal behaviour, is there an alternative to listview('refresh'), like listview('appended'), that just selects the items after ".ui-last-item"? Currently I have a workaround where I put appended items into a hidden list, call .listview('refresh') on that, and then move the list items into my visible list.
We just looked into this and turned out my previous comment was incorrect. When I made the change to not add class
At a glance from those commits it looks like it might be because I'm using autodividers? I figure this might be written so that if a list is using autodividers, the entire list is refreshed in order to prevent a duplicate divider appearing in the appended content that is already present further up the list.
If that's the case, in my workaround, where I'm appending to and then copying from a hidden list, I'm preventing this by doing:
Which is all I need to do to get rid of duplicate divider, I don't need the whole list refreshing.
Anyway, I might be wrong, I'll try turning off dividers and see if I still have the performance issue.
Ok here's a fiddle:
Just crack open the console and scroll down the listview.
In my testing it went from 0.01 seconds with 6 list items to 0.3 seconds with 400.
Obviously that's nowhere near the slow-down I was experiencing, but shows that the refresh is targeting more than just already enhanced list items.
Ah my last test was on my desktop machine. On my Nexus 7 the stats were more like the slow-down I was seeing in my app.
1.004 seconds with 120 items.
Edit: Forgot to mention that without autodividers it was twice as fast, but still getting increasingly slower as the list grew (0.46 seconds with 120 items). Here's my fork of the last fiddle without autodividers http://jsfiddle.net/dA8PS/1/
Edit again: Realise in my jsfiddle I was using jquery mobile 1.2, but I just tested again with 1.3 and the results were pretty much identical.
referenced this issue
Sep 17, 2014
So the code for this has not changed we are still iterating over the entire list. This is something we need to look at when we re-write listview in general it should not be an issue even with large numbers of elements as in general essentially nothing is done to each in the loop if already enhanced. I want to keep this open just so its not forgotten when we do get to re-writing listview.