繁体   English   中英

DataZombies-iScroll在克隆的div上不起作用

[英]DataZombies - iScroll not working on cloned divs

我正在从动态提取的数据中克隆<li>模板和后续的<div>模板( <li>链接至)。 创建列表后,我可以使用以下命令刷新s-scrollwrapper:$('#rlist')。data('iscroll')。refresh(); 这很棒。 但是,当涉及到模板时,我没有运气让每个模板都刷新。 我已经尝试了上述方法,jQT.setPageHeight(); 链接<li> onClick方法以及创建每个<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(); 
} 

似乎没有任何作用。 在这个问题上的任何帮助,我将不胜感激。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM