extjsextjs6-classicextjs6-modern

How to display data from store in Ext.Component ExtJS


I have store which return data from server:

Ext.define('Admin.store.dashboard.NPS', {
extend: 'Ext.data.Store',
alias: 'store.nps',

autoLoad : false,
proxy    : {
    type: 'api',
    url : SITE_URL + '/api/surveys/nps'
},
fields   : [
    {
        type: 'float',
        name: 'nps'
    }
]    
});

And I want to display that data in tpl of Ext.Component:

Ext.define('Admin.view.dashboard.NPSPercent', {
extend: 'Ext.Component',
xtype: 'nps-percent',
bind: {
    data: {
        nps_percent: '{nps}'
    }
},

tpl: new Ext.XTemplate('<div class="percent">+{nps_percent.nps}</div>')
});

I tried bind data to loaded store but it dose not work.


Solution

  • Templates in components expect regular things like arrays, not stores. To render a template using a store as the datasource, use Ext.view.View class instead of just a component.