To ensure that the developer's dataproxy API is used correctly, we define an API for Ext. Data. API Singleton to manage the data. In addition to defining the four crud operations: Get, view, change, and destroy, these operations are also mapped to restful HTTP methods: Get, post, put, and delete.
Let's take a look at the source code. VaR validactions ={} is to save the "reverse Ext. Data. API. Actions hash table hash", that is, the value is changed to a key. In this example, some methods (such as getactions and getverb) Take for (VAR verb in this. actions) Statements traverse these actions, so in order to be more efficient, the accessed hash will be saved as a cache, and some methods will first check the matched values in the hash. Note that this hash is constantly read, written, and modified during its operation, so we cannot predefine this hash.
The attribute actions specifies the local actions associated with remote actions, such:
Actions: {<br/> Create: 'create', // indicates the creation action performed by the log created on the server. Text representing the remote-action to create records on server. <br/> Read: 'read', // indicates the creation action performed by the server to read and load data. Text representing the remote-Action to read/load data from server. <br/> Update: 'update', // indicates the creation action performed by the update record on the server. Text representing the remote-action to update records on server. <br/> destroy: 'deststroy' // indicates the creation action performed by the log deleted on the server. Text representing the remote-action to destroy records on server. <br/>}
As for the attribute restactions, the {crud action }:{ HTTP Method} pair that defines the HTTP method and the associated action will be used for Ext. Data. dataproxy. restful. Default Value:
Restactions: {<br/> Create: 'post', <br/> Read: 'get', <br/> Update: 'put', <br/> destroy: 'delete' <br/>}
Run the Ext. Data. API. isaction (Action) method. If the input action name already exists in the constant Ext. Data. API. Actions, true is returned. The parameters of this method can also be an array of crud operations. It is faster to input arrays when multiple operations are performed.
Execute getverb (name) to return the actual CRUD operation key value, and identify the actual "CREATE", "read", "Update" or "Destroy" operation type based on the input action name. Generally, this method is used internally and will not be called directly. The key/value pairs of Ext. Data. API. Actions are the same, but they are not necessarily the same. If necessary, developers can overwrite the specified name. However, the framework calls methods based on keys. Therefore, you need to obtain the "Create", "read", "Update", and "Destroy" keywords in some way. If it is found that the keys have been cached in validactions, it will be returned directly from the cache.
Isvalid (): If the input API is valid, true is returned. In this way, the predefined action is checked and passed in to the array, the final response (incorrect action ).
Hasuniqueurl () is used when the incoming proxy returns true when there is no other API operation in the original unique proxy address. This issue is important when you decide whether to insert the "xaction" HTTP parameter to an Ajax request. Generally, this method is used internally and will not be called directly.
The prepare (ext. Data. dataproxy) method is used internally by Ext. Data. dataproxy, which is generally not suitable for direct use. During Internal definition, each dataproxy API action can be a string or an object. When defined as an object, you can precisely specify the HTTP method (get, post…) for the CRUD operation ...). This method initializes the passed API and converts each operation into an object. If the HTTP method is not set for the API you pass in, the configuration item specified by "method" is the default method. If the configuration item of method is not specified, it is post.
New Ext. Data. httpproxy ({<br/> method: "Post", // The default HTTP method is not specified. <Br/> API: {<br/> Create: 'create. PHP ', <br/> load: 'read. PHP ', <br/> Save: 'save. php', <br/> destroy: 'Destroy. php' <br/>}< br/> });
// Optional. It can also be defined as an object. <Br/> New Ext. data. httpproxy ({<br/> API: {<br/> load: {URL: 'read. PHP ', method: 'get'}, <br/> Create: 'create. php', <br/> destroy: 'Destroy. php', <br/> Save: 'Update. php' <br/>}< br/> });
By executing restify (), you can initialize the proxy to make it restful. You can define the HTTP method (get, post, put, delete) for each API action based on the value of restactions ).
Finally, ext provides us with an exception class Ext. Data. API. error to report any exception information to users.