javascript - Jquery mobile (ListView) trigger create slow when tried to insert large number of rows -
i have found problem , solutions in other pages still cannot perfect one.
i looping through array of 200 objects.
var stringbuffer = []; for(var = 0; < array; i++) { stringbuffer.push('<input type="radio" class="select_options" data-iconpos="right" onclick ="callclosepopup(event);" name="items" id="radio_' + array[i].conditionid + '" ' + checked + 'value="' + array[i].conditionid+'_' + array[i].description + '"/><label data-corners="false" data-iconshadow="false" style="border-bottom:1px solid rgb(0,0,0)" for="radio_' + array[i].conditionid + '">' + array[i].description + '</label>'); } var combinedhtml = stringbuffer.join("") $("#mylistview").html(combinedhtml).trigger("create"); <=== line consumes lot of time (around 9 seconds on moto g).
any ideas improve this?
ps: using jquerymobile v-1.3.1.
i've not tried implementing this, may rough solution. i'm looking more elegant project.
this provided zupkoo
html:
<div id="test"></div>
js:
$.mobile.showpageloadingmsg(); var s = ""; var of; of = $("#test"); of.append(s); of.trigger("create"); for(var =0;i<350;i++){ s+="<form>"; s+="<input type=\"checkbox\" id=\"checkbox-"+i+"\" />"; s+="<label for=\"checkbox-"+i+"\">"+i+"</label>"; s+="</form>"; } var srclength = 1000; var srcnumb = 1000; var startsrc = 0; var ss =""; var inter=self.setinterval(function(){ if(s.length <= (startsrc+srclength)){ ss=s.substr(startsrc); of.append(ss); of.trigger("create"); clearinterval(inter);$.mobile.hidepageloadingmsg(); }else{ ss = s.substr((startsrc),srclength); var index = ss.indexof("</form>",(srclength-200)); srcnumb=index+7;//</form> = 7 startsrc+=srcnumb; of.append(ss.substr(0,srcnumb)); of.trigger("create"); } },0);
Comments
Post a Comment