Search code examples
extjsextjs6extjs6-classic

changeItemTpl dynamically depending data jsonStore


I am a beginner in the classic of Sencha ExtJS!

I need to change the content to dataview itemTpl.

Here is my data from jsonstore:

{
    success: true,
    items: {
        idTipoActividad: 1,
        Ejercicios: [{
            idimgCorrect: 1,
            nameAudio: 'brother-in-law',
            images: [{
                id: 1,
                filename: 'https://www.abc.es/Media/201308/01/1--644x362.jpg'
            }, {
                id: 2,
                filename: 'https://www.abc.es/Media/201308/01/1--644x362.jpg'
            }, {
                id: 3,
                filename: 'https://www.abc.es/Media/201308/01/1--644x362.jpg'
            }, {
                id: 4,
                filename: 'https://www.abc.es/Media/201308/01/1--644x362.jpg'
            }]
        }, {
            idimgCorrect: 2,
            nameAudio: 'Home',
            images: [{
                id: 1,
                filename: 'https://upload.wikimedia.org/wikipedia/commons/0/0d/SEAT_600_SIAM_2008.JPG'
            }, {
                id: 2,
                filename: 'https://upload.wikimedia.org/wikipedia/commons/0/0d/SEAT_600_SIAM_2008.JPG'
            }, {
                id: 3,
                filename: 'https://upload.wikimedia.org/wikipedia/commons/0/0d/SEAT_600_SIAM_2008.JPG'
            }, {
                id: 4,
                filename: 'https://upload.wikimedia.org/wikipedia/commons/0/0d/SEAT_600_SIAM_2008.JPG'
            }]
        }]
    }
}

The array Ejercicios should to change with click button and show in itemTpl Here is my fiddle


Solution

  • Use tpl instead of itemTpl and attach below function to dataview:

    setTemplate: function (template, itemSelector) {
        this.tpl = template;
        this.itemSelector = itemSelector;
        this.refresh();
    }
    

    and use it in your onBtnNextClick1 function like below:

    refs.viewImages.setTemplate(tpl, 'div.container');
    

    Working fiddle

    Note: Please check AudioImagen3.js and MyWindow3ViewController4.js in fiddle for detailed info. (I have corrected couple of code too.)

    Hope this will help/guide you.