Reputation: 237
I have read many other posts with this same question, but none seem to give me the answer I need to fix the issue.
I have defined my datastore as below:
Ext.define('TestApp.store.tbData', {
extend: 'Ext.data.Store',
alias: 'store.tbData',
storeId: 'tbData',
fields: [
'name', 'number', 'key', 'priority'
],
data: {
items: [
{name: 'a', number: 'b', key: 'c', priority: 'd'}
]
},
proxy: {
type: 'memory',
reader: {
type: 'json',
rootProperty: 'items'
}
}
});
Then I also have my main view:
Ext.define('TestApp.Templates.tbTemplate', {
extend: 'Ext.window.Window',
alias: 'tbTemplate',
itemId: 'tbWindow',
viewModel: {
type: 'test'
},
requires: [
'TestApp.Controllers.tbController',
'TestApp.store.tbData',
'TestApp.Controllers.dateTimeController'
],
controller: 'tbTemplate',
autoShow: true,
height: 600,
width: 600,
constrainHeader: true,
title: 'tb',
items: [
{
xtype: 'gridpanel',
store: {
type: 'tbData'
},
columns: [
{
xtype: 'gridcolumn',
dataIndex: 'name',
text: 'Name'
},
{
xtype: 'gridcolumn',
dataIndex: 'number',
text: 'Number'
},
{
xtype: 'gridcolumn',
dataIndex: 'key',
text: 'Key'
},
{
xtype: 'gridcolumn',
dataIndex: 'priority',
text: 'Priority'
}
]
}
]
});
Which has a controller:
Ext.define('TestApp.Controllers.tbController', {
extend: 'Ext.app.ViewController',
singleton: true,
alias: 'controller.tbTemplate',
config:{stores: ['tbData'],},
requires: [
'TestApp.store.tbData'
],
windowOpened: function () {
console.log(Ext.getStore('tbData'));
}
});
In the controller, when i call the windowOpened function, I am trying to get the datastore, so eventually I can add some more rows of data to it dynamically. I can display the test data I have put in the row, but I can't seem to connect to the datastore the way I have tried. Any help would be appreciated as to why it is returning undefined and how to tackle it.
I have tried adding it to my Application.js folder using
stores: ['TestApp.store.tbData']
with no luck either.
Thanks.
Upvotes: 0
Views: 14973
Reputation: 223
You can try the following inside windowOpened:
var store = Ext.StoreManager.lookup('tbData');
console.log(store);
or
var store = this.getViewModel().getStore('tbData');
console.log(store);
Upvotes: 0
Reputation: 176
Actually i am not familiar with extjs 6 but i read your code and i am not understand how to bind your window opened event to controller function. so i tried your code on fiddle and it wasn't work. So i read a little bit docs about how to bind it. This is the my modifies on your code and it seems work.
Upvotes: 3