As we all know, a tool like Vs.net remembers when we last closed: the position of each window, size, toolbar status, custom menu items, and so on. This is undoubtedly a function to use. ExtJS also contains a state-saving mechanism whose main controls: Girdpanel,formpanel, and so on, all provide state-saving functionality. What we need is just to provide it with the right provider.
1, save the state of the client
Let's take a look at the process of persisting the control state when a control state changes in a ExtJS:
The first two steps (red) in the process are responsible for the control. When a control state changes, it uses JSON to serialize its state, and then calls the Ext.state.Manager.getProvider () static method to obtain the provider of the current program configuration, and then invokes the provider set method to save its state. What we need to do is to provide a provider, and when its set method is invoked, it is OK to save the state of the control passed over to the server. The code for the provider is as follows:
1:srims.providerctor = Ext.extend (Ext.state.Provider, {
2:
3:get:function (name, defaultvalue) {
4://alert (' get: ' + name + ': ' + srims.provider._state[name]);
5://return DefaultValue;
6:
7:if (Srims.provider._state[name])
8:return Ext.util.JSON.decode (Srims.provider._state[name]);
9:
10:return DefaultValue;
11:},
12:set:function (name, value) {
//alert (' Set: ' + name + ' + Ext.util.JSON.encode (value));
14:var valuestring = Ext.util.JSON.encode (value)
15:srims.provider._state[name] = valuestring;
16:
17:ext.ajax.request ({
18:url: '/user.asmx/setextclientstate ',
19:method: ' POST ',
20:params: {
21:key:name,
22:value:valuestring
23:}
24:});
25:},
26:clear:function (name) {
27:srims.provider._state[name] = undefined;
28:}
29:});
30:
31:srims.provider = new Srims.providerctor ();
32:srims.provider._state = new function () {
33:};