问题
I create a window containing grids that send off ajax requests. Now, I immediatley close the window again before the grids are fully created and the ajax requests return.
I have two problems:
- My components within a window are still "alive" after a window is destroyed
Chrome console lists them. Although my window has the autoDestroy: true
the gridpanel and store are still existing after the window is closed. When closed, the destroy
event is fired. Docs say, all components under the window should be destroyed.
- Then my callbacks finally return and get executed but the window is destroyed
The problem is, that the callbacks try to reconfigure a grid that has no more store attached.
Error: Uncaught TypeError: Cannot call method 'getCount' of null Table.js:500
(/lib/extjs/src/view/Table.js
How can I stop the callbacks from processing if my window is destroyed?
回答1:
Registering the events with mon so that they get removed when the listening object get destroyed. Alternatively you may:
- remove them manually within the destroy() method
- check within the callback for methods or properties that may not exist to skip them
Edit
There are some more things that you can do
- check if the destroy() methods of the grids get called
- abort all request by calling Ext.Ajax.abortAll() (before the window close)
- abort just specific requestst by calling Ext.Ajax.abort(request) (before the window close)
I recommend to use option 2. because it should be the safest.
Edit 2
To take a look at all running request you need to look at the private requests
property of Ext.data.Connection
from which Ext.Ajax
extend. requests
is of type object and will contain a property (the request Id) for each request that is currently running.
来源:https://stackoverflow.com/questions/17591127/how-to-handle-incoming-ajax-requests-after-destroying-window