

Set the method attribute to the name of the method that creates a view object. Set the module attribute to the name of the module.

For instructions on adding a module to your project, see Using Titanium Modules.Īdd the Module tag in to an Alloy view as a child of a window or another parent object depending on the view object returned by the module. To use the Module tag:Īdd the module to your project. You can also include a view from a native module using the Module XML element. In the Alloy view, to include this object, add the Foo tag and set the module attribute to foo. Custom attributes of the element are passed to the public method.įor example, the following CommonJS module, called foo.js, exposes the createFoo method, which returns a Label object inside a View object. This method also must return a Titanium UI object that can be added to the view.Īdd the element to the Alloy view and set the module attribute to the path (after the app/lib folder) and name of the CommonJS module minus the extension. This CommonJS module must expose a public method called create, where is used as the XML element in the Alloy view. Place the CommonJS module in your project's app/lib folder.

You can require a CommonJS module in an Alloy view using the module attribute of an XML element. set ( 'author', 'William Shakespeare' ) # Module attribute
#Buttonbar doclick code#
js extension) to the end of it.įor example, the code below creates a collection singleton based on a model called book:ĭrama. To access the collection from a controller, use the Alloy.Collections namespace and append the model filename (minus the. To create a singleton, use the Collection tag and assign the src attribute to the model file minus the. The collection singleton is available in the Alloy.Collections namespace for the controller code to access. The Collection tag needs to be a child of the Alloy parent tag. The Collection XML element creates a singleton or instance of a collection. Most examples are in the components under the Titanium.UI section and also in, , Modules.Map and. Other views do not have any format restrictions.įor examples, refer to the 'Alloy XML Markup' examples in the Titanium API Guides (opens new window) site. Index.xml is a special case that only accepts the following view components as direct children of the Alloy tag: Same as the Require element with the type specified to 'widget'. See the Require element for more details. Imports a widget or includes another view inside this view. See the Collection element for more details.Ĭreates a singleton or instance of the specified model. Required in all views.Ĭreates a singleton or instance of the specified collection. The following table lists the special XML elements besides the Titanium UI components: Element See Property mapping for more details.Īssigns callbacks to UI object events. See Conditional code and Namespace for more details.Īssigns values to UI object properties. Values can be any combination of platforms. Switches the namespace based on the platform and acts as a compiler directive for platform-specific view components. Overrides the default Titanium.UI namespace. Note that the XML element must be named after a create method in the module. See Conditional code and Alloy Styles and Themes: Custom Query Styles for more details. Use a custom query to apply additional styles to the element. See Dynamic Styles: Autostyle for more details.Īcts as a compiler directive for size-specific view components. Overwrites the element style but not the id style.Įnables the autostyle feature for dynamic styling when adding or removing classes. IDs should be unique per view but are not global, so multiple views can have components with the same ID.Īpplies additional styles (prefixed with. Identifies UI elements in the controller (prefixed with $.) and style sheet (prefixed with #). The following table lists the attributes for the UI components: Attribute For this example, the code would need be placed in app/controllers/index.js. In Alloy, your JavaScript code and Titanium API calls need to be placed in the associated controller file to the view. In the previous example, the win.open call and implementation of the doClick callback are missing.
