Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs store.load does not make the call

I have the code ExtJs 4 :

var proxy = Ext.create('Ext.data.Proxy',  {
type : 'ajax',
    url : 'some url',
    reader : {
        type : 'json'
    }
});
myStore.setProxy(proxy);  
myStore.load({   // this never loads, no error in console either
    scope : this,
    params : {
    },
    callback: function() {
    }
});
like image 448
fastcodejava Avatar asked Mar 23 '23 07:03

fastcodejava


1 Answers

Your problem is that you are trying to define a type while creating a concrete instance of the superclass. type is a valid configuration when you are defining a proxy within a configuration of a class like a Ext.data.Model (which is the recommend way in most situations!) Following is a example how it should be done:

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name', 'email']
});

//The Store contains the AjaxProxy as an inline configuration
var store = Ext.create('Ext.data.Store', {
    model: 'User',
    proxy: {
        type: 'ajax',
        url : 'users.json'
    }
});

store.load();

The Store will now instantiate the proxy by using the applied type property, in this case ajax. The proxy line above is the same as

new Ext.data.proxy.Ajax({
    url: 'users.json',
    model: 'User',
    reader: 'json'
});

So type is a valid property as long as you use it in configurations of classes that consume a proxy like Ext.data.Model or Ext.data.Store

And if you ever need to create a proxy instance yourself you will need to create the concrete instance. Superclasses has documented their direct subclasses in the API

enter image description here

but in case of the reader that doesn't help because you only find Server & Client but they are listed in the class description section Types of Proxy

Types of Proxy

There are two main types of Proxy - Client and Server. The Client proxies save their data locally and include the following subclasses:

  • LocalStorageProxy - saves its data to localStorage if the browser supports it
  • SessionStorageProxy - saves its data to sessionStorage if the browsers supports it
  • MemoryProxy - holds data in memory only, any data is lost when the page is refreshed

The Server proxies save their data by sending requests to some remote server. These proxies include:

  • Ajax - sends requests to a server on the same domain
  • JsonP - uses JSON-P to send requests to a server on a different domain
  • Rest - uses RESTful HTTP methods (GET/PUT/POST/DELETE) to communicate with server
  • Direct - uses Ext.direct.Manager to send requests

Proxies operate on the principle that all operations performed are either Create, Read, Update or Delete. These four operations are mapped to the methods create, read, update and destroy respectively. Each Proxy subclass implements these functions.

The CRUD methods each expect an Operation object as the sole argument. The Operation encapsulates information about the action the Store wishes to perform, the model instances that are to be modified, etc. See the Operation documentation for more details. Each CRUD method also accepts a callback function to be called asynchronously on completion.

Proxies also support batching of Operations via a batch object, invoked by the batch method.

Available since: 1.1.0

like image 52
sra Avatar answered Apr 20 '23 20:04

sra