[SOLVED] Virtual List Item Call Method

I want to call method for newly added list elements.

‘<img @click="$root.openImageUrlBrowser(’ + ‘{{this.assetList[0].path}}’ + ‘)" />’

Virtual list code

app.virtualList.create({
                    el: '#form-virtual-list',
                    items: nList,
                    searchAll: function (query, items) {
                        var found = [];

                            if (items[i].name.toLowerCase().indexOf(query.toLowerCase()) >= 0 || query                                  .trim() === '')
                                found.push(i);

                        }

                        return found; //return array with mathced indexes

                    },

                    // List item Template7 template

                    itemTemplate: '<li>' +
                        '<div class="item-content">' +
                        '<div class="item-media">' +
                        '{{#if this.assetList[0]}}' +
                        '<img data-src="{{this.assetList[0].path}}" class="lazy lazy-fade-in" width="60"' +
                        '@click="$root.openImageUrlBrowser(' +
                        '{{this.assetList[0].path}}' + ')" />' +
                        '{{else}}<i class="icon f7-icons">bookmark</i>{{/if}}' +
                        '</div>' +
                        ' <div class="item-inner">' +  
                        '<div class="item-title-row">' +
                        '<div class="item-title"> {{this.name}}</div>' +
                        '</div>' +
                        '<div class="item-subtitle"> {{this.code}} - {{this.description}}</div>' +
                        '</div>' +
                        '<div class="item-after row">' +
                        '<a href="/form-detail/{{this.id}}/{{this.code}}/" class="col-100 link margin-bottom-icon"><i class="icon f7-icons">chevron_right</i></a>' +
                        '<a href="/ambalage-find-list/{{this.code}}/" class="col-100 link"><i class="icon f7-icons">cube</i></a>' +
                        ' </div>' +
                        '</div>' +
                        '</li>',
                    // Item height
                    height: app.theme === 'ios' ? 63 : (app.theme === 'md' ? 73 : 46),

                });

It is not possible to use @ event handlers in VL item template. Check forum search, there were solutions on how to do it, or check this KS example how to use VL with VDOM https://github.com/framework7io/framework7/blob/master/kitchen-sink/core/pages/virtual-list-vdom.html

1 Like