I have a json data chunk of about 9000 items.
I’m using in for three virtualLists, for the same use (select an item and add into lists/cart)
The first VirtualList works perfectly.
The secondth VL prints only the first hundred results, and after bugs. If i try to search on items, the VL don’t find items that haven’t been printed.
For the third VL, i’m only have tenth per cent of the secondth VL results.
Maybe it’s a copy paste problem, but i’m wondering…
Here is the 1st one :
var virtualList = app.virtualList.create({
el: '.virtual-list',
items: gameItems,
searchAll: function (query, items) {
var games_found = [];
for (var i = 0; i < gameItems.length; i++) {
if (gameItems[i].title.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') games_found.push(i);
}
return games_found; //return array with mathced indexes
},
itemTemplate:
'<li>' +
'<a href="#" class="item-link item-content" data-item-id="{{id}}">' +
'<div class="item-inner">' +
'<div class="item-title-row">' +
'<div class="item-title">{{title}} {{#if inLudo}}<span class="badge color-green">Ludothèque</span>{{/if}}</div>' +
'</div>' +
'</div>' +
'</a>' +
'</li>',
// Item height
height: app.theme === 'ios' ? 63 : 73,
on: {
itemsAfterInsert: function (fragment) {
let listLastItems = this.filteredItems;
for(kitem in listLastItems){
let a = $$('a[data-item-id="'+ listLastItems[kitem].id + '"]');
if (a[0] !== undefined){
aClone = a[0].cloneNode(true);
$$(aClone).on('click', function(ev){
let post_id = $$(this).data('item-id');
app.request.post(THEMEREX_ajax_url, { token: API_profile_token, controler: 'Ludotheque', action: 'addInLudo', user: userId, post_id: post_id }, function (data) {
app.router.navigate('/games/', { reloadCurrent: true });
});
});
a.parent()[0].replaceChild(aClone, a[0]);
}
}
}
}
});
The secondth now :
var VAddGameToPlay = app.virtualList.create({
el: '.add-game-to-play',
items: game_items,
showFilteredItemsOnly: false,
searchAll: function (query, game_items) {
var games_for_plays_found = [];
for (var i = 0; i < items.length; i++) {
if (game_items[i].title.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') games_for_plays_found.push(i);
}
return games_for_plays_found; //return array with matched indexes
},
itemTemplate:
'<li>' +
'<a href="#" class="item-link item-content" data-item-id="{{id}}">' +
'<div class="item-inner">' +
'<div class="item-title-row">' +
'<div class="item-title">{{title}}</div>' +
'</div>' +
'</div>' +
'</a>' +
'</li>',
height: app.theme === 'ios' ? 63 : 73,
on: {
itemsAfterInsert: function (fragment) {
let listLastItems = this.filteredItems;
for(kitem in listLastItems){
let a = $$('a[data-item-id="'+ listLastItems[kitem].id + '"]');
if (a[0] !== undefined){
aClone = a[0].cloneNode(true);
$$(aClone).on('click', function(ev){
let post_id = $$(this).data('item-id');
app.request.post(THEMEREX_ajax_url, { token: API_profile_token, controler: 'Ludotheque', action: 'addInLudo', user: userId, post_id: post_id }, function (data) {
app.router.navigate('/games/', { reloadCurrent: true });
});
});
a.parent()[0].replaceChild(aClone, a[0]);
}
}
}
}
});
And finally :
var VAddGameToList = app.virtualList.create({
el: '.add-game-to-list',
items: game_items_for_lists,
searchAll: function (query, game_items) {
var games_for_list_found = [];
for (var i = 0; i < items.length; i++) {
if (game_items_for_lists[i].title.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query.trim() === '') games_for_list_found.push(i);
}
return games_for_list_found; //return array with matched indexes
},
itemTemplate:
'<li>' +
'<a href="#" class="item-link item-content" data-item-id="{{id}}">' +
'<div class="item-inner">' +
'<div class="item-title-row">' +
'<div class="item-title">{{title}}</div>' +
'</div>' +
'</div>' +
'</a>' +
'</li>',
height: app.theme === 'ios' ? 63 : 73,
on: {
itemsAfterInsert: function (fragment) {
page.route.route.methods.addToTop(topId);
// une fois la recherche commencé on remet les événements
VAddGameToList.on('itemsAfterInsert', function(fragment){
page.route.route.methods.addToTop(topId);
});
}
}
});
I’m goin’ nuts !!