DataZombies - iScroll无法处理克隆的div

时间:2011-10-15 01:33:30

标签: javascript jqtouch iscroll4

  

我正在克隆<li>模板和后续<div>模板(到   其中<li>链接来自动态提取的数据。列表之后   创建我能够使用这个刷新s-scrollwrapper:$   。( '#rlist')数据( 'iscroll')刷新();这很棒。但是,当它   来到模板我没有运气得到每一个   他们要刷新。我试过上面的方法了   jQT.setPageHeight();方法同时从链接<li>和   每个<div>创建时。我甚至试过添加一个新的s-   scrollwrapper进入已经形成的<divs>似乎没有   工作

    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(); 
} 
  

似乎没什么用。我很感激在这个问题上的任何帮助。

1 个答案:

答案 0 :(得分:0)

感谢您使用我的代码。 HTML标记中的每个ID都必须是唯一的,否则您的JavaScript将无效。当你为div着色时,你也复制了div的ID。我的代码使用.s-scrollwrapper类动态地为div分配了一个基于页面ID的ID。修改代码中的页面ID应该可以解决问题。还要在代码中包含以下内容以设置所有内容。

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