Current location - Loan Platform Complete Network - Foreign exchange account opening - How does ext.js call the interface written in the store?
How does ext.js call the interface written in the store?
Calling the interface written in ExtJS can be realized by the following steps:

1. Define a Store object and set its proxy property to the URL of the API interface, for example:

```

ext . define(' myapp . store . my store ',{

Extension:' Ext.data.Store',

Alias: "store.mystore",

Model,' MyApp.model.MyModel',

Proxy server: {

Type: "ajax",

Url: '/api/data',//Here is the URL of the api interface.

Reader: {

Type:' json',

RootProperty: "data"

}

}

});

```

In the above code, the' proxy' attribute is used to specify the loading and saving method of data. Here, an ajax proxy is used, and the URL is set to' /api/data'.

2. Instantiate this Store object where the interface needs to be called, and call its `load ()' method to load data, for example:

```

var my store = ext . create(' myapp . store . my store ');

myStore.load({

Callback: Function (Record, Operation, Success) {

//Call back function after data loading is completed

If (successful) {

//Data loaded successfully

//The loaded data can be further processed here.

} Otherwise {

//Data loading failed

//You can handle errors here.

}

}

});

```

In the above code, the MyStore' object is instantiated by the create ()' method, and then the' load ()' method is called to load the data. In the loaded callback function, the loaded data can be further processed.

Reason: The Store object in ExtJS is used to manage the interaction between front-end applications and back-end data. By setting the proxy property of the store to the URL of the API interface, you can tell the store where to get the data. After calling the `load () ` method of the Store, ExtJS will automatically send Ajax requests to the specified API interface and load the obtained data into the Store.

Extended content: In addition to calling the interface to obtain data, the Store also provides other methods and events for adding, deleting, modifying and querying data. For example, you can use the store's' add ()' method to add new records, use the' remove ()' method to delete records, and use the' sync ()' method to save the modified data to the back end. In addition, stores can also bind components such as grids and forms to display and edit data. Through in-depth study of API documents and store examples, we can better understand and use the data management functions in ExtJS.