DataZombies - iScroll不工作的克隆div的
问题描述:
我克隆既是
<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();
}
似乎没有任何工作。我很感谢在这个问题上的任何帮助。
答
感谢您使用我的代码。您的HTML标记中的每个ID必须是唯一的,否则您的JavaScript将无法工作。当你着色div时,你也会复制div的ID。我的代码动态地为.s-scrollwrapper类分配了一个基于页面ID的ID。在你的代码中修改页面的ID应该可以做到。在你的代码中还包括以下内容来设置一切。
init_iScroll('<new page's div>');