I’m not using renderItem for this… I am just using itemTemplate which is a string containing HTML tags with handlebar variable references. Should I use renderItem for this instead?
//itemTemplate => remove it
renderItem:function(item){
var obj=app.utils.extend(item,{index:this.items.indexOf(item)});
var tmpl='<li>\
<p>{{index}}</p>\
<p>{{title}}</p>\
</li>';
return Template7.compile(tmpl)(obj);
},
Great! This is getting somewhere!
Now to extend my question, is there a way that items can be an object with keys rather than a basic array? If so, how would this new renderItem function have to look?
Cool. I just thought I’d ask because my original data is in object form and I have been using Object.values( itemsObject ) to convert it for the virtualList display, but I’m worried this isn’t supported on android as it seems to be breaking. Is there a better way to do this?
Thanks for this. Is this more efficient than Object.values()? And do you think my use of this is causing my problems in Android? I read it may not be supported.
var obj={};
for(var i=0;i<1000000;i++){
obj[i]=i;
}
console.time("x");
var arr1=Object.values(obj)
console.timeEnd("x")
console.time("y");
var arr2=[];
for(var k in obj){
arr2.push(obj[k]);
}
console.timeEnd("y");
That’s weird. I ran your example ten times and my results point to the other being faster.
x: 574.723ms / y: 404.666ms
x: 501.143ms / y: 309.576ms
x: 511.628ms / y: 323.977ms
x: 484.237ms / y: 321.076ms
x: 486.238ms / y: 326.444ms
x: 504.114ms / y: 366.733ms
x: 509.089ms / y: 343.915ms
x: 475.865ms / y: 347.020ms
x: 492.772ms / y: 320.431ms
x: 488.557ms / y: 334.067ms
Either way, the best thing would be to not have to convert the object to an array for the virtualList or autoComplete. I guess that’s just not an option right?