Hi All,
I've so far managed to get iscroll to work with the entire list dynamically loaded.
My index.html page snippet:
- <div data-role="page" class="mainPage">
- <div data-role=content" class="content">
- <!-- dynamic content gets loaded here -->
- </div>
- </div>
My externally loaded page summarised:
- <div class="listviewWrapper">
- <div class="iscroll-pulldown">
- <span class="iscroll-pull-icon"></span>
- <span class="iscroll-pull-label"></span>
- </div>
-
- <ul data-role="listview" class="myList">
- <!-- ...losts of data... -->
- </ul>
-
- <div class="iscroll-pullup">
- <span class="iscroll-pull-icon"></span>
- <span class="iscroll-pull-label" data-iscroll-loading-text="Loading" data-iscroll-pulled-text="Pull up for more">
- </div>
-
- </div>
My JS snippet:
- $(document).live('pageinit', function(){
- loadPages("content", "listview.html", ["listviewWrapper"]);
- });
-
- function loadPages(divClass, contentFile, listOfScrollerWrappers){
- $("."+ divClass).empty();
-
- $.get(contentFile, function(data){
- $(data).appendTo($("."+ divClass)).trigger('create');
-
- if(listOfScrollerWrappers != null){
- for(var i = 0; i < listOfScrollerWrappers.length; i++){
- var scrollerTemp = $("."+ listOfScrollerWrappers[i]);
- scrollerTemp.attr("data-iscroll","");
- scrollerTemp.iscrollview();
- scrollerTemp.iscrollview("refresh");
- }
- }
- }
-
- $(document).delegate("div.mainPage", "pageinit", function(){
- $(". content").bind({
- iscroll_onpullup : onListPullUp
- });
- });
-
- function onListPullUp(event, data){
- setTimeout(function(){
- getMainListviewPullUpData(event, data);
- }, 1500);
- }
-
- var pullUpGeneratedCount = 0;
- var listSelector = "div.listviewWrapper";
- var lastItemSelector = listSelector + " ui.myList > li:last-child";
-
- function gotPullUpData(event, data) {
- var iscrollview = data.iscrollview;
- var newContent = "";
-
- for (var i=0; i<3; i++) {
- newContent += "<li>Pullup-generated row " + (++pullUpGeneratedCount) + "</li>";
- }
-
- $(listSelector).append(newContent).listview("refresh");
- scrollview.refresh(null, null,
- $.proxy(function afterRefreshCallback() {
- this.scrollToElement(lastItemSelector, 400);
- }, iscrollview)
- );
- }
This is all fine and all (as in iscroll works the way it's expected when the content is loaded) but I have three issues.
1. The pull up event is triggered twice as generated row counts from 1 to 6 on first pull up.
2. I get an uncaught error like so:
Uncaught Error: cannot call methods on iscrollview prior to initialization; attempted to call method 'refresh'
3. The scrollToElement part does not do anything at all.
Does anyone have a solution to fix both my problems. Although the first issue is the main priority at the moment as it's causing the application to not run as expected. The second doesn't seem to make any difference as long as the refresh method is the last thing I call in that function. And the third issue can be removed if I have to (don't really care if I have that or not).