1

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.

Andriy Yushko
  • 395
  • 5
  • 21

1 Answers1

2

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.

Coderino Javarino
  • 2,819
  • 4
  • 21
  • 43
  • I have viewModel in my parent view where included my component. So it means that all child element have access to viewModel parent view. – Andriy Yushko Jan 29 '19 at 15:54
  • 1
    Not something I'd recommend (in projects of decent size at least). If you need data from parent component's vm, it's usually better to define a config in the child, and get that config bound to vm inside the parent. – Coderino Javarino Jan 29 '19 at 15:58