I try to use Ext.Direct with the ExtJS 4 MVC structure, and I'm not able to add the provider.
I get the error Uncaught TypeError: Cannot call method 'addProvider' of undefined
while calling addProvider
:
Ext.Direct.addProvider(Ext.app.REMOTING_API);
I tried both in launch
of the application and in init
of the controller.
Ext.define('Dir.Application', {
require: [
'Ext.direct.*',
'Ext.data.*',
'Ext.grid.*'
],
launch: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
and
Ext.define('Dir.controller.Main', {
init: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
both give the same error.
Where is the correct location to put addProvider
into the code ?
Ext.define('Dir.Application', {
view:['Grid'],
requires: [
'Ext.direct.*',
'Ext.data.*',
'Ext.grid.*'
],
launch: function(){
Ext.Direct.addProvider(Ext.app.REMOTING_API);
}
...
});
My view is defining a store and a proxy:
Ext.define('Dir.view.Grid', {
extend: 'Ext.grid.Panel',
store: {
proxy: {
type: 'direct',
reader:{root: 'table'},
api: {
create: QueryDatabase.createRecord,
read: QueryDatabase.getResults,
update: QueryDatabase.updateRecords,
destroy: QueryDatabase.destroyRecord
}
}
...
}
Now the first error is OK, but I receiver an error complaining that QueryDatabase
is not defined. It gets defined through the provider at Ext.Direct.addProvider(Ext.app.REMOTING_API);
but it is not ready when the view is loaded through the views: []
declaration in the application definition.
Is there a way to get this working without nesting Ext.application
inside Ext.onReady
like in my solution?
No nesting would be better for the MVC way like explained here in the docs.
The require
in your application definition won't do anything. It should be plural requires
.
Also, you seem to have devised this in your own answer, but the name Ext.direct.Manager
seems to be the favored by Sencha over Ext.Direct
now.
Edit
According to the docs, you can set your direct functions using a string. Apparently, this is intended to solve exactly the kind of problems you've run into.
This should work and fix your issue:
api: {
create: 'QueryDatabase.createRecord',
read: 'QueryDatabase.getResults',
update: 'QueryDatabase.updateRecords',
destroy: 'QueryDatabase.destroyRecord'
}