2011-10-15 81 views
0

我克隆既是<li>模板和隨後的<div>模板(以 該<li>鏈接)從動態數據拉。在創建列表 後,我可以使用以下命令刷新s-scrollwrapper:$ ('#rlist')。data('iscroll')。refresh();這很棒。但是,當它 來到模板我沒有運氣,讓他們刷新每個 。我試過上面的方法, jQT.setPageHeight();方法兩個onClick從鏈接<li>和 當每個<div>被創建。我甚至嘗試在已經形成的<divs>中追加一個新的s- 滾動包裝器,其中沒有一個似乎 工作。DataZombies - iScroll不工作的克隆div的

function loadInfo(){ 
... 
fillRedSection(availableArray, $('#entryTemplate')); 
$('#rlist').data('iscroll').refresh(); 
//Tried ways to refresh scroll of the cloned divs...nothing seems to 
work 
} 

function fillRedSection(arr, template){ 
    //iterating through the JSON data 
    for (i = 0; i<arr.length; i++){ 
     var dataLocation = arr; //Data arr 
     var row = dataLocation[i].id; //id# coming with JSON data 
     var newEntryRow = template.clone(); //cloned <li> template 
from HTML 
     newEntryRow.removeAttr('id'); 
     newEntryRow.removeAttr('style'); //removing hidden style 
     newEntryRow.attr('id', 'red-label'+row); //renaming the <li> 
id with the id from JSON 
     newEntryRow.attr('class', 'arrow'); //JQT class 
     newEntryRow.appendTo('#redlist ul'); //placing cloned <li> 
into ul 
     newEntryRow.find('a').attr('href','#red-'+row);//renaming href 
so it will link to the cloned <div> 
      var newEntryDetails = $('#red-description').clone(true, 
true);//cloning the div template 
      newEntryDetails.removeAttr('id'); 
      newEntryDetails.removeAttr('style');//removing hidden 
style 
      newEntryDetails.attr('id', 'reds-'+row);//renaming id so 
the <li> href can link to it 
      //1 Possible attempt at adding the scroll class as each 
div is created 
      // Hopefully avoiding problem of cloned scrolls with the 
same id name 
      /*var newScroll = $('.tester'); 
      newScroll.removeAttr('id'); 
      newScroll.attr('id', 'scroll-'+row); 
      newScroll.attr('class', 's-scrollwrapper');*/ 
      newEntryDetails.appendTo('#jqt'); //append cloned <div> to 
the main <#jqt> div. 
newEntryDetails.find('h4').text(dataLocation[i].business_name);// 
filling div from JSON 
     ... 
    } 
} 

//Attempt to refresh iScroll on the div that is being clicked on from 
the <li> 
//used onClick="refreshScroll() 
refreshScroll { 
jQT.setPageHeight(); 
} 

似乎沒有任何工作。我很感謝在這個問題上的任何幫助。

回答

0

感謝您使用我的代碼。您的HTML標記中的每個ID必須是唯一的,否則您的JavaScript將無法工作。當你着色div時,你也會複製div的ID。我的代碼動態地爲.s-scrollwrapper類分配了一個基於頁面ID的ID。在你的代碼中修改頁面的ID應該可以做到。在你的代碼中還包括以下內容來設置一切。

init_iScroll('<new page's div>');