Ext.NET
5.3.0
.NET Component Framework for Enterprise Level Apps
|
Controllers are the glue that binds an application together. All they really do is listen for events (usually from views) and take some action. Here's how we might create a Controller to manage Users: More...
Classes | |
class | Builder |
class | Config |
Public Member Functions | |
XController () | |
virtual string | ToScript (System.Web.UI.Control owner) |
XController.Builder | ToBuilder () |
override IControlBuilder | ToNativeBuilder () |
XController (Config config) | |
Public Member Functions inherited from Ext.Net.Observable | |
virtual void | AddListener (string eventName, JFunction fn) |
Appends an event handler to this component More... | |
virtual void | AddListener (string eventName, JFunction fn, string scope) |
Appends an event handler to this component More... | |
virtual void | AddListener (string eventName, JFunction fn, string scope, HandlerConfig options) |
Appends an event handler to this component More... | |
virtual void | AddListener (string eventName, string fn) |
Appends an event handler to this component More... | |
virtual void | AddListener (string eventName, string fn, string scope) |
Appends an event handler to this component More... | |
virtual void | AddListener (string eventName, string fn, string scope, HandlerConfig options) |
Appends an event handler to this component More... | |
virtual void | AddManagedListener (string item, string eventName, string fn, string scope, HandlerConfig options) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | AddManagedListener (string item, string eventName, string fn, string scope) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | AddManagedListener (string item, string eventName, string fn) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | ClearListeners () |
Removes all listeners for this object including the managed listeners More... | |
virtual void | ClearManagedListeners () |
Removes all managed listeners for this object. More... | |
virtual void | EnableBubble (params string[] events) |
Enables events fired by this Observable to bubble up an owner hierarchy by calling this.getBubbleTarget() if present. There is no implementation in the Observable base class. This is commonly used by Ext.Components to bubble events to owner Containers. See Ext.AbstractComponent-getBubbleTarget. The default implementation in Ext.AbstractComponent returns the AbstractComponent's immediate owner. But if a known target is required, this can be overridden to access the required target more quickly. More... | |
virtual void | FireEvent (string eventName, params object[] args) |
Fires the specified event with the passed parameters (minus the event name) More... | |
virtual void | FireEventedAction (string eventName, object[] args, string fn) |
Fires the specified event with the passed parameters and executes a function (action). Evented Actions will automatically dispatch a 'before' event passing. This event will be given a special controller that allows for pausing/resuming of the event flow. By pausing the controller the updater and events will not run until resumed. Pausing, however, will not stop the processing of any other before events. More... | |
virtual void | FireEventedAction (string eventName, object[] args, string fn, string scope) |
Fires the specified event with the passed parameters and executes a function (action). Evented Actions will automatically dispatch a 'before' event passing. This event will be given a special controller that allows for pausing/resuming of the event flow. By pausing the controller the updater and events will not run until resumed. Pausing, however, will not stop the processing of any other before events. More... | |
virtual void | FireEventedAction (string eventName, object[] args, string fn, string scope, object[] fnArgs) |
Fires the specified event with the passed parameters and executes a function (action). Evented Actions will automatically dispatch a 'before' event passing. This event will be given a special controller that allows for pausing/resuming of the event flow. By pausing the controller the updater and events will not run until resumed. Pausing, however, will not stop the processing of any other before events. More... | |
virtual void | FireEventedAction (string eventName, object[] args, JFunction fn) |
Fires the specified event with the passed parameters and executes a function (action). Evented Actions will automatically dispatch a 'before' event passing. This event will be given a special controller that allows for pausing/resuming of the event flow. By pausing the controller the updater and events will not run until resumed. Pausing, however, will not stop the processing of any other before events. More... | |
virtual void | FireEventedAction (string eventName, object[] args, JFunction fn, string scope) |
Fires the specified event with the passed parameters and executes a function (action). Evented Actions will automatically dispatch a 'before' event passing. This event will be given a special controller that allows for pausing/resuming of the event flow. By pausing the controller the updater and events will not run until resumed. Pausing, however, will not stop the processing of any other before events. More... | |
virtual void | FireEventedAction (string eventName, object[] args, JFunction fn, string scope, object[] fnArgs) |
Fires the specified event with the passed parameters and executes a function (action). Evented Actions will automatically dispatch a 'before' event passing. This event will be given a special controller that allows for pausing/resuming of the event flow. By pausing the controller the updater and events will not run until resumed. Pausing, however, will not stop the processing of any other before events. More... | |
virtual void | On (string eventName, string fn) |
Appends an event handler to this element (shorthand for addListener) More... | |
virtual void | On (string eventName, string fn, string scope) |
Appends an event handler to this element (shorthand for addListener) More... | |
virtual void | On (string eventName, string fn, string scope, HandlerConfig options) |
Appends an event handler to this element (shorthand for addListener) More... | |
virtual void | On (string eventName, JFunction fn) |
Appends an event handler to this element (shorthand for addListener) More... | |
virtual void | On (string eventName, JFunction fn, string scope) |
Appends an event handler to this element (shorthand for addListener) More... | |
virtual void | On (string eventName, JFunction fn, string scope, HandlerConfig options) |
Appends an event handler to this element (shorthand for addListener) More... | |
virtual void | RelayEvents (string origin, string[] events) |
Relays selected events from the specified Observable as if the events were fired by this. More... | |
virtual void | RemoveListener (string eventName, string fn) |
Removes an event handler. More... | |
virtual void | RemoveListener (string eventName, string fn, string scope) |
Removes an event handler. More... | |
virtual void | RemoveManagedListener (string item, string eventName, string fn) |
Removes listeners that were added by the mon method. More... | |
virtual void | RemoveManagedListener (string item, string eventName, string fn, string scope) |
Removes listeners that were added by the mon method. More... | |
virtual void | ResumeEvents () |
Resume firing events. (see suspendEvents) If events were suspended using the queueSuspended parameter, then all events fired during event suspension will be sent to any listeners now. More... | |
virtual void | SuspendEvents (bool queueSuspended) |
Suspend the firing of all events. (see resumeEvents) More... | |
virtual void | SuspendEvents () |
Suspend the firing of all events. (see resumeEvents) More... | |
virtual void | SuspendEvent (string name) |
Suspends firing of the named event(s). More... | |
virtual void | ResumeEvent (string name) |
Resumes firing of the named event(s). More... | |
virtual void | RemoveDirectListener (string name) |
virtual void | Un (string eventName, string fn) |
Removes a listener (shorthand for removeListener) More... | |
virtual void | Un (string eventName, string fn, string scope) |
Removes a listener (shorthand for removeListener) More... | |
virtual void | Mon (Element el, string eventName, JFunction fn) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | Mon (Observable el, string eventName, JFunction fn) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | Mon (Element el, string eventName, JFunction fn, string scope) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | Mon (Observable el, string eventName, JFunction fn, string scope) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | Mon (Element el, string eventName, string fn, string scope, HandlerConfig options) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | Mon (Observable el, string eventName, string fn, string scope, HandlerConfig options) |
Adds listeners to any Observable object (or Element) which are automatically removed when this AbstractComponent is destroyed. More... | |
virtual void | Mun (Element el, string eventName, string fn) |
Removes listeners that were added by the mon method. More... | |
virtual void | Mun (Observable el, string eventName, string fn) |
Removes listeners that were added by the mon method. More... | |
virtual void | Mun (Element el, string eventName, string fn, string scope) |
Removes listeners that were added by the mon method. More... | |
virtual void | Mun (Observable el, string eventName, string fn, string scope) |
Removes listeners that were added by the mon method. More... | |
delegate void | OnBeforeClientInitializedHandler (Observable sender) |
delegate void | OnAfterClientInitializedHandler (Observable sender) |
Public Member Functions inherited from Ext.Net.BaseControl | |
virtual bool | HasExplicitValue (string name) |
virtual T | ToBuilder< T > () |
T | Apply< T > (IApply config) |
object | Apply (IApply config) |
BaseControl | Apply (object from, bool ignoreDefaultValues) |
BaseControl | Apply (object from) |
virtual bool | HasLayout () |
virtual bool | HasContent () |
virtual string | ResolveUrlLink (string url) |
bool | IsInHierarchy (params Type[] types) |
T | GetParentByLevel< T > (int level) |
virtual string | DefineInstance () |
virtual string | DefineInstance (string config) |
virtual string | DefineInstance (string instanceOf, string config) |
virtual string | ToConfig () |
virtual string | ToConfig (LazyMode mode) |
virtual string | ToConfig (LazyMode mode, bool registerResourcesInManager) |
virtual string | ToScript (bool selfRendering) |
virtual string | ToScript () |
string | ToScript (RenderMode mode, string element) |
string | ToScript (RenderMode mode, string element, bool selfRendering) |
string | ToScript (RenderMode mode, string element, int index) |
string | ToScript (RenderMode mode, string element, int index, bool selfRendering) |
string | ToScript (RenderMode mode, string element, int? index, bool? selfRendering, bool forceResources, string method, bool forceLazy, bool clearContainer) |
virtual void | AddScript (string script) |
Adds the script to be be called on the client. More... | |
virtual void | AddScript (string template, params object[] args) |
Adds the script to be be called on the client. The script is formatted using the template and args. More... | |
virtual void | Set (string name, object value) |
virtual void | Set (ScriptPosition position, string name, object value) |
virtual void | Call (string name) |
virtual void | Call (string name, params object[] args) |
virtual void | Call (string name, string[] arg) |
Calls the JavaScript function on the Control with a string[] parameter More... | |
virtual void | Call (ScriptPosition mode, string name, params object[] args) |
virtual string | SelfRender () |
virtual void | AddBeforeClientInitScript (string script) |
Adds the script directly before the ClientInitScript. More... | |
virtual void | AddAfterClientInitScript (string script) |
Adds the script directly after the ClientInitScript. More... | |
override void | RenderBeginTag (HtmlTextWriter writer) |
virtual void | Render (bool selfRendering) |
virtual void | Render (Control control) |
virtual void | Render () |
virtual void | Render (string element, RenderMode mode) |
virtual void | Render (string element, int index, RenderMode mode) |
virtual void | Render (Control control, RenderMode mode) |
virtual void | Render (Control control, int index, RenderMode mode) |
virtual void | Render (string element, RenderMode mode, bool selfRendering) |
virtual void | Render (string element, int index, RenderMode mode, bool selfRendering) |
virtual void | Render (RenderMode mode, string element, int? index, bool? selfRendering, bool forceResources, string method, bool forceLazy, bool clearContainer) |
virtual void | Render (Control control, RenderMode mode, bool selfRendering) |
virtual void | Render (Control control, int index, RenderMode mode, bool selfRendering) |
virtual void | AddTo (string element) |
virtual void | AddTo (Control control) |
virtual void | AddTo (string element, bool selfRendering) |
virtual void | AddTo (Control control, bool selfRendering) |
virtual void | InsertTo (int index, string element) |
virtual void | InsertTo (int index, Control control) |
virtual void | InsertTo (int index, string element, bool selfRendering) |
virtual void | InsertTo (int index, Control control, bool selfRendering) |
virtual void | Update () |
virtual bool | SuspendScripting () |
virtual void | ResumeScripting (bool oldValue) |
virtual void | ResumeScripting () |
virtual void | Destroy () |
List< T > | GetCustomResources< T > () |
virtual void | SetResources () |
List< ClientStyleItem > | GetStyles () |
List< ClientStyleItem > | GetThemes () |
List< ClientScriptItem > | GetScripts () |
string | GetGeneratedScripts () |
Get generated and added javascript methods calling More... | |
virtual bool | HasOwnState (string name) |
virtual void | SetControlFor (ModelMetadata meta) |
Public Member Functions inherited from Ext.Net.ICustomConfigSerialization | |
string | ToScript (Control owner) |
Static Public Member Functions | |
static implicit | operator XController (XController.Config config) |
Static Public Member Functions inherited from Ext.Net.BaseControl | |
static string | GenerateID () |
static object | Apply (object to, object from) |
static object | Apply (object to, object from, bool ignoreDefaultValues) |
Additional Inherited Members | |
Protected Member Functions inherited from Ext.Net.Observable | |
override void | OnInit (EventArgs e) |
virtual void | RegisterCustomAttribute (string key, string value) |
virtual void | OnBeforeClientInit (Observable sender) |
virtual void | OnAfterClientInit (Observable sender) |
virtual void | OnBeforeClientInitHandler () |
virtual void | OnAfterClientInitHandler () |
override void | OnPreRender (EventArgs e) |
override void | PreRenderAction () |
virtual void | AfterItemAdd (Observable item) |
virtual void | AfterItemRemove (Observable item) |
override void | SetModelAdditionalValue (KeyValuePair< string, object > value) |
Protected Member Functions inherited from Ext.Net.BaseControl | |
virtual string | GetNamespace (bool parseDot) |
virtual string | AddNamespaceToID (string id) |
virtual ContentContainer | CreateContainer () |
virtual void | CheckForceId () |
virtual string | ParseTarget (string target) |
Unit | UnitPixelTypeCheck (object obj, Unit defaultValue, string propertyName) |
virtual void | CallTemplate (string template) |
virtual void | CallTemplate (string template, string name, params object[] args) |
virtual void | CallTemplate (ScriptPosition position, string template, string name, params object[] args) |
override void | OnInit (EventArgs e) |
virtual void | PagePreLoad (object sender, EventArgs e) |
virtual void | PageLoad (object sender, EventArgs e) |
virtual void | PageLoadComplete (object sender, EventArgs e) |
override void | AddAttributesToRender (HtmlTextWriter writer) |
virtual void | SimpleRender (HtmlTextWriter writer) |
virtual void | RecreateChildControls () |
override void | CreateChildControls () |
override void | OnPreRender (EventArgs e) |
virtual void | RenderScript (string script) |
override void | OnDataBinding (EventArgs e) |
override void | Render (HtmlTextWriter writer) |
virtual bool | IsGlobalResourceRegistered (ResourceItem item) |
virtual string | FormatValue (object value, string format) |
virtual void | OnMetadataProcess (ModelMetadata meta, string name, ViewDataDictionary viewData, ControllerContext context) |
virtual void | SetModelValidationRule (ModelClientValidationRule rule) |
virtual void | SetModelValue (object value, ModelMetadata meta) |
Properties inherited from Ext.Net.XControllerBase | |
virtual string[] | ModelNames [get, set] |
Array of models to require from AppName.model namespace. More... | |
virtual ItemsCollection< Model > | Models [get] |
IList< string > | ModelsProxy [get] |
virtual string[] | StoreNames [get, set] |
Array of stores to require from AppName.store namespace and to generate getter methods for. More... | |
virtual ItemsCollection< AbstractStore > | Stores [get] |
IList< string > | StoresProxy [get] |
virtual List< AppRef > | Refs [get] |
Array of configs to build up references to views on page. More... | |
virtual string[] | ViewNames [get, set] |
Array of views to require from AppName.view namespace and to generate getter methods for. More... | |
virtual string | Name [get, set] |
The controller name. Required More... | |
virtual string | StoreTokens [get] |
virtual string | ModelTokens [get] |
override ConfigOptionsCollection | ConfigOptions [get] |
Properties inherited from Ext.Net.Observable | |
virtual List< Observable >?? | LazyItems [get] |
virtual bool | SingleItemMode [get] |
virtual ConfigItemCollection?? | CustomConfig [get] |
Collection of custom js config More... | |
DynamicConfigDictionary | ConfigsProxy [get] |
virtual string | DirectEventsKey [get] |
MessageBusListeners | MessageBusListeners [get] |
MessageBusDirectEvents | MessageBusDirectEvents [get] |
virtual string | MessageBusListenersProxy [get] |
virtual string | MessageBusDirectEventsProxy [get] |
override ConfigOptionsCollection | ConfigOptions [get] |
Properties inherited from Ext.Net.BaseControl | |
string | ProductName [get] |
The product name More... | |
virtual string | Version [get] |
The Version number of this build More... | |
string | DynamicID [get] |
override string | ID [get, set] |
The unique id of this component instance (defaults to an auto-assigned id). Components created with an id may be accessed globally using Ext.getCmp. You can use the itemId config, and ComponentQuery which provides selector-based searching for Sencha Components analogous to DOM querying. The Container class contains shortcut methods to query its descendant Components by selector. Note that this id will also be used as the element id for the containing HTML element that is rendered to the page for this component. This allows you to write id-based CSS rules to style the specific instance of this component uniquely, and also to select sub-elements using this component's id as the parent. Note: to avoid complications imposed by a unique id also see itemId. Note: to access the container of a AbstractComponent see ownerCt. More... | |
override string | ClientID [get] |
virtual string | ItemID [get, set] |
An itemId can be used as an alternative way to get a reference to a component when no object reference is available. Instead of using an id with Ext.getCmp, use itemId with Ext.container.Container.getComponent which will retrieve itemId's or id's. Since itemId's are an index to the container's internal MixedCollection, the itemId is scoped locally to the container – avoiding potential conflicts with Ext.ComponentMgr which requires a unique id More... | |
virtual string???? | ConfigID [get] |
virtual string | BaseClientID [get] |
The base .ClientID property derived from .NET Framework More... | |
virtual string | ConfigIDProxy [get] |
bool | HasOwnIDMode [get] |
virtual IDMode | IDMode [get, set] |
Options for controlling how the .ClientID property is rendered in the client. More... | |
virtual bool | StopIDModeInheritance [get, set] |
virtual bool | StopLazyModeInheritance [get, set] |
virtual LazyMode? | LazyMode [get, set] |
Options for controlling how the lazy control is instantiated in the client. More... | |
bool | HasOwnNamespace [get] |
virtual string | ClientNamespace [get] |
virtual string | Namespace [get, set] |
virtual string? | ClientNamespaceProxy [get] |
virtual string??? | InitialConfig [get] |
This AbstractComponent's initial configuration specification. Read-only. More... | |
virtual bool | AutoDataBind [get, set] |
virtual FactoryConfig | Factory [get, set] |
virtual string | FactoryAlias [get, set] |
virtual string | FactoryInstance [get, set] |
virtual bool | TemplateWidget [get, set] |
virtual string | TemplateWidgetFnName [get, set] |
virtual ConfigOptionsCollection | ConfigOptions [get] |
virtual ConfigOptionsExtraction | ConfigOptionsExtraction [get] |
virtual DefaultValueMode | DefaultValueMode [get, set] |
virtual bool | RemoveContainer [get] |
virtual bool | IsMVC [get] |
static ClientScriptItem | UXScriptItem [get] |
static ClientStyleItem | UXStyleItem [get] |
virtual bool | IsDebugging [get] |
virtual bool | IsAjaxRequestInitiator [get] |
virtual bool | IsDefault [get] |
Does this object currently represent it's default state. More... | |
virtual bool | IsLazy [get] |
virtual string? | ContainerID [get] |
virtual string | ContainerStyle [get] |
virtual bool | IsInHead [get] |
virtual bool | IsInForm [get] |
virtual string | ClientForm [get] |
virtual System.Web.UI.HtmlControls.HtmlForm | ParentForm [get] |
virtual AbstractComponent | ParentComponent [get] |
virtual BaseControl | ParentWebControl [get] |
virtual string | InstanceOf [get] |
virtual string | AliasPrefix [get] |
virtual string? | ClassName [get] |
virtual string | CallID [get] |
virtual bool | IsGeneratedID [get] |
bool | IsDynamic [get, set] |
Set to true if a control is meant to be dynamically rendered. In absolutely most cases, this is set to true automatically if needed and originally the property was internal. Though, in some very specific and edge cases a developer might need to set it to true by his own. Setting it to true you should be absolutelly sure it is required. For example, if it is recommended by Ext.NET support team. Also it can be changed only to true, but not backwards. Defaults to false. More... | |
virtual bool | ContentUpdated [get, set] |
string | BeforeScript [get] |
string | AfterScript [get] |
virtual AbstractComponent | ParentComponentNotLazyOrDynamic [get] |
virtual bool | RenderTags [get] |
bool | RegisterAllResources [get, set] |
override string | ToolTip [get, set] |
override string | AccessKey [get, set] |
override Color | BackColor [get, set] |
override Color | BorderColor [get, set] |
override System.Web.UI.WebControls.BorderStyle | BorderStyle [get, set] |
override System.Web.UI.WebControls.Unit | BorderWidth [get, set] |
override string | CssClass [get, set] |
override System.Web.UI.WebControls.FontInfo | Font [get] |
override Color | ForeColor [get, set] |
override Unit | Height [get, set] |
override Unit | Width [get, set] |
virtual string | PostBackArgument [get, set] |
virtual string | PostBackConfig [get] |
virtual bool | HasResourceManager [get] |
virtual ResourceManager | ResourceManager [get] |
virtual List< ResourceItem > | Resources [get] |
virtual List< ClientResourceItem > | ResourceItems [get] |
virtual List< ResourceItem > | GlobalResources [get] |
virtual string? | ClientInitScript [get] |
virtual bool | IsInUpdatePanelRefresh [get] |
virtual Control | MyUpdatePanel [get] |
System.Web.Mvc.HtmlHelper?? | HtmlHelper [get, set] |
System.Web.Mvc.ViewContext | ViewContext [get, set] |
System.Web.Mvc.ControllerBase | Controller [get, set] |
virtual ViewDataDictionary | ViewData [get] |
virtual ControllerContext | ControllerContext [get] |
virtual string | ControlFor [get, set] |
virtual bool | IDFromControlFor [get, set] |
string | FormatControlForValue [get, set] |
Func< object, object > | ConvertControlForValue [get, set] |
Properties inherited from Ext.Net.IXObject | |
ConfigOptionsCollection | ConfigOptions [get] |
ConfigOptionsExtraction | ConfigOptionsExtraction [get] |
DefaultValueMode | DefaultValueMode [get, set] |
Properties inherited from Ext.Net.ILazyItems | |
List< Observable > | LazyItems [get] |
Events inherited from Ext.Net.Observable | |
OnBeforeClientInitializedHandler | BeforeClientInit |
OnAfterClientInitializedHandler | AfterClientInit |
Controllers are the glue that binds an application together. All they really do is listen for events (usually from views) and take some action. Here's how we might create a Controller to manage Users:
Ext.define('MyApp.controller.Users', { extend: 'Ext.app.Controller',
init: function() { console.log('Initialized Users! This happens before ' + 'the Application launch() function is called'); } }); The init function is a special method that is called when your application boots. It is called before the Application's launch function is executed so gives a hook point to run any code before your Viewport is created.
The init function is a great place to set up how your controller interacts with the view, and is usually used in conjunction with another Controller function - control. The control function makes it easy to listen to events on your view classes and take some action with a handler function. Let's update our Users controller to tell us when the panel is rendered:
Ext.define('MyApp.controller.Users', { extend: 'Ext.app.Controller',
init: function() { this.control({ 'viewport > panel': { render: this.onPanelRendered } }); },
onPanelRendered: function() { console.log('The panel was rendered'); } }); We've updated the init function to use control method to set up listeners on views in our application. The control method uses the ComponentQuery engine to quickly and easily get references to components on the page. If you are not familiar with ComponentQuery yet, be sure to check out the documentation. In brief though, it allows us to pass a CSS-like selector that will find every matching component on the page.
In our init function above we supplied 'viewport > panel', which translates to "find me every Panel that is a direct child of a Viewport". We then supplied an object that maps event names (just 'render' in this case) to handler functions. The overall effect is that whenever any component that matches our selector fires a 'render' event, our onPanelRendered function is called.
Event domains
In Ext JS 4.2, we introduced the concept of event domains. In terms of MVC, an event domain is one or more base classes that fire events to which a Controller wants to listen. Besides Component event domain that encompass Ext.Component-descended Views, Controllers now can listen to events from data Stores, Ext.Direct Providers, other Controllers, and Ext.globalEvents. This feature provides a way to communicate between parts of the whole application without the need to bind controllers together tightly, and allows to develop and test application parts in isolation.
See usage examples in listen method documentation.
Using refs
One of the most useful parts of Controllers is the ref system. These use the Ext.ComponentQuery to make it really easy to get references to Views on your page. Let's look at an example of this now:
Ext.define('MyApp.controller.Users', { extend: 'Ext.app.Controller',
refs: [{ ref: 'list', selector: 'grid' }],
init: function() { this.control({ 'button': { click: this.refreshGrid } }); },
refreshGrid: function() { this.getList().store.load(); } }); This example assumes the existence of a Grid on the page, which contains a single button to refresh the Grid when clicked. In our refs array, we set up a reference to the grid. There are two parts to this - the 'selector', which is a ComponentQuery selector which finds any grid on the page and assigns it to the reference 'list'.
By giving the reference a name, we get a number of things for free. The first is the getList function that we use in the refreshGrid method above. This is generated automatically by the Controller based on the name of our ref, which was capitalized and prepended with get to go from 'list' to 'getList'.
The way this works is that the first time getList is called by your code, the ComponentQuery selector is run and the first component that matches the selector ('grid' in this case) will be returned. All future calls to getList will use a cached reference to that grid. Usually it is advised to use a specific ComponentQuery selector that will only match a single View in your application (in the case above our selector will match any grid on the page).
Bringing it all together, our init function is called when the application boots, at which time we call this.control to listen to any click on a button and call our refreshGrid function (again, this will match any button on the page so we advise a more specific selector than just 'button', but have left it this way for simplicity). When the button is clicked we use out getList function to refresh the grid.
You can create any number of refs and control any number of components this way, simply adding more functions to your Controller as you go. For an example of real-world usage of Controllers see the Feed Viewer example in the examples/app/feed-viewer folder in the SDK download.
Generated getter methods
Refs aren't the only thing that generate convenient getter methods. Controllers often have to deal with Models and Stores so the framework offers a couple of easy ways to get access to those too. Let's look at another example:
Ext.define('MyApp.controller.Users', { extend: 'Ext.app.Controller', models: ['User'], stores: ['AllUsers', 'AdminUsers'],
init: function() { var User, allUsers, ed;
User = this.getUserModel(); allUsers = this.getAllUsersStore();
ed = new User({ name: 'Ed' }); allUsers.add(ed); } }); By specifying Models and Stores that the Controller cares about, it again dynamically loads them from the appropriate locations (app/model/User.js, app/store/AllUsers.js and app/store/AdminUsers.js in this case) and creates getter functions for them all. The example above will create a new User model instance and add it to the AllUsers Store. Of course, you could do anything in this function but in this case we just did something simple to demonstrate the functionality.
|
inline |
|
inline |
|
inlinestatic |
|
inline |
|
inlinevirtual |
Reimplemented from Ext.Net.BaseControl.
|
inlinevirtual |
owner |