Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / docs / api / Ext.ModelManager.html
1 <!DOCTYPE html><html><head><title>Ext.ModelManager | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
2 <style type="text/css">.head-band { display: none; }
3 .header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
4 .doc-tab .members .member a.more { background-color: #efefef; }
5 </style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
6 </head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
7 <a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">
8
9     req = {
10         liveURL: '.',
11         standAloneMode: true,
12         origDocClass: 'Ext.ModelManager',
13         docClass: 'Ext.ModelManager',
14         docReq: 'Ext.ModelManager',
15         version: '4.0',
16         baseURL: '.',
17         baseDocURL: '.',
18         baseProdURL: '.'
19     };
20
21     clsInfo = {};
22
23
24
25 </script>
26
27 <script type="text/javascript" src="../search.js"></script>
28 <!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
29 <script type="text/javascript" src="../class_tree.js"></script>
30 <script type="text/javascript" src="../class_doc.js"></script>
31 <script type="text/javascript">
32     req.source = 'ModelManager.html#Ext-ModelManager';
33     clsInfo = {"methods":["create","each","get","getCount","getModel","isRegistered","onAvailable","register","registerType","unregister"],"cfgs":[],"properties":["all","associationStack"],"events":[],"subclasses":[]};
34     Ext.onReady(function() {
35         Ext.create('Docs.classPanel');
36     });
37 </script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/ModelManager.html#Ext-ModelManager" target="_blank">Ext.ModelManager</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><pre class="subclasses"><h4>Hierarchy</h4><div class="subclass f"><a href="Ext.AbstractManager.html" rel="Ext.AbstractManager" class="cls docClass">Ext.AbstractManager</a><div class="subclass"><strong>Ext.ModelManager</strong></div></div></pre><p>The ModelManager keeps track of all <a href="Ext.data.Model.html" rel="Ext.data.Model" class="docClass">Ext.data.Model</a> types defined in your application.</p>
38
39 <p><strong>Creating Model Instances</strong>
40 Model instances can be created by using the <a href="Ext.ModelManager.html#create" rel="Ext.ModelManager#create" class="docClass">create</a> function. It is also possible to do
41 this by using the Model type directly. The following snippets are equivalent:</p>
42
43 <pre class="prettyprint"><code>Ext.define('User', {
44     extend: 'Ext.data.Model',
45     fields: ['first', 'last']
46 });
47
48 // method 1, create through the manager
49 Ext.ModelManager.create({
50     first: 'Ed',
51     last: 'Spencer'
52 }, 'User');
53
54 // method 2, create on the type directly
55 new User({
56     first: 'Ed',
57     last: 'Spencer'
58 });
59 </code></pre>
60
61 <p><strong>Accessing Model Types</strong>
62 A reference to a Model type can be obtained by using the <a href="Ext.ModelManager.html#getModel" rel="Ext.ModelManager#getModel" class="docClass">getModel</a> function. Since models types
63 are normal classes, you can access the type directly. The following snippets are equivalent:</p>
64
65 <pre class="prettyprint"><code>Ext.define('User', {
66     extend: 'Ext.data.Model',
67     fields: ['first', 'last']
68 });
69
70 // method 1, access model type through the manager
71 var UserType = Ext.ModelManager.getModel('User');
72
73 // method 2, reference the type directly
74 var UserType = User;
75 </code></pre>
76 <div class="members"><div class="m-properties"><a name="properties"></a><div class="definedBy">Defined By</div><h3 class="prp p">Properties</h3><div id="property-all" class="member f inherited"><a href="Ext.ModelManager.html#property-all" rel="property-all" class="expand more"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-property-all" class="viewSource">view source</a></div><a name="all"></a><a name="property-all"></a><a href="Ext.ModelManager.html#" rel="property-all" class="cls expand">all</a><span> : Ext.util.MixedCollection</span></div><div class="description"><div class="short"><p>Contains all of the items currently managed</p>
77 </div><div class="long"><p>Contains all of the items currently managed</p>
78 </div></div></div><div id="property-associationStack" class="member ni"><a href="Ext.ModelManager.html#property-associationStack" rel="property-associationStack" class="expand more"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.ModelManager.html" class="definedIn docClass">Ext.ModelManager</a><br/><a href="../source/ModelManager.html#Ext-ModelManager-property-associationStack" class="viewSource">view source</a></div><a name="associationStack"></a><a name="property-associationStack"></a><a href="Ext.ModelManager.html#" rel="property-associationStack" class="cls expand">associationStack</a><span> : Array</span></div><div class="description"><div class="short"><p>Private stack of associations that must be created once their associated model has been defined</p>
79 </div><div class="long"><p>Private stack of associations that must be created once their associated model has been defined</p>
80 </div></div></div></div><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-create" class="member f ni"><a href="Ext.ModelManager.html#method-create" rel="method-create" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.ModelManager.html" class="definedIn docClass">Ext.ModelManager</a><br/><a href="../source/ModelManager.html#Ext-ModelManager-method-create" class="viewSource">view source</a></div><a name="create"></a><a name="method-create"></a><a href="Ext.ModelManager.html#" rel="method-create" class="cls expand">create</a>(
81 <span class="pre">Object data, String name, Number id</span>)
82  : void</div><div class="description"><div class="short"><p>Creates a new instance of a Model using the given data.</p>
83 </div><div class="long"><p>Creates a new instance of a Model using the given data.</p>
84 <h3 class="pa">Parameters</h3><ul><li><span class="pre">data</span> : Object<div class="sub-desc"><p>Data to initialize the Model's fields with</p>
85 </div></li><li><span class="pre">name</span> : String<div class="sub-desc"><p>The name of the model to create</p>
86 </div></li><li><span class="pre">id</span> : Number<div class="sub-desc"><p>Optional unique id of the Model instance (see <a href="Ext.data.Model.html" rel="Ext.data.Model" class="docClass">Ext.data.Model</a>)</p>
87 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
88 </li></ul></div></div></div><div id="method-each" class="member inherited"><a href="Ext.ModelManager.html#method-each" rel="method-each" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-each" class="viewSource">view source</a></div><a name="each"></a><a name="method-each"></a><a href="Ext.ModelManager.html#" rel="method-each" class="cls expand">each</a>(
89 <span class="pre">Object fn, Object scope</span>)
90  : void</div><div class="description"><div class="short">Executes the specified function once for each item in the collection.
91 Returning false from the function will cease it...</div><div class="long"><p>Executes the specified function once for each item in the collection.
92 Returning false from the function will cease iteration.</p>
93
94 <p>The paramaters passed to the function are:</p>
95
96 <div class="mdetail-params"><ul>
97 <li><b>key</b> : String<p class="sub-desc">The key of the item</p></li>
98 <li><b>value</b> : Number<p class="sub-desc">The value of the item</p></li>
99 <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
100 </ul></div>
101
102 <h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Object<div class="sub-desc"><p>The function to execute.</p>
103 </div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>The scope to execute in. Defaults to <tt>this</tt>.</p>
104 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
105 </li></ul></div></div></div><div id="method-get" class="member inherited"><a href="Ext.ModelManager.html#method-get" rel="method-get" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-get" class="viewSource">view source</a></div><a name="get"></a><a name="method-get"></a><a href="Ext.ModelManager.html#" rel="method-get" class="cls expand">get</a>(
106 <span class="pre">String id</span>)
107  : Mixed</div><div class="description"><div class="short"><p>Returns an item by id.
108 For additional details see <a href="Ext.util.HashMap.html#get" rel="Ext.util.HashMap#get" class="docClass">Ext.util.HashMap.get</a>.</p>
109 </div><div class="long"><p>Returns an item by id.
110 For additional details see <a href="Ext.util.HashMap.html#get" rel="Ext.util.HashMap#get" class="docClass">Ext.util.HashMap.get</a>.</p>
111 <h3 class="pa">Parameters</h3><ul><li><span class="pre">id</span> : String<div class="sub-desc"><p>The id of the item</p>
112 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Mixed</span>&nbsp; &nbsp;<p>The item, <code>undefined</code> if not found.</p>
113 </li></ul></div></div></div><div id="method-getCount" class="member inherited"><a href="Ext.ModelManager.html#method-getCount" rel="method-getCount" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-getCount" class="viewSource">view source</a></div><a name="getCount"></a><a name="method-getCount"></a><a href="Ext.ModelManager.html#" rel="method-getCount" class="cls expand">getCount</a> : Number</div><div class="description"><div class="short"><p>Gets the number of items in the collection.</p>
114 </div><div class="long"><p>Gets the number of items in the collection.</p>
115 <h3 class="pa">Returns</h3><ul><li><span class="pre">Number</span>&nbsp; &nbsp;<p>The number of items in the collection.</p>
116 </li></ul></div></div></div><div id="method-getModel" class="member ni"><a href="Ext.ModelManager.html#method-getModel" rel="method-getModel" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.ModelManager.html" class="definedIn docClass">Ext.ModelManager</a><br/><a href="../source/ModelManager.html#Ext-ModelManager-method-getModel" class="viewSource">view source</a></div><a name="getModel"></a><a name="method-getModel"></a><a href="Ext.ModelManager.html#" rel="method-getModel" class="cls expand">getModel</a>(
117 <span class="pre">String/Object id</span>)
118  : void</div><div class="description"><div class="short"><p>Returns the <a href="Ext.data.Model.html" rel="Ext.data.Model" class="docClass">Ext.data.Model</a> for a given model name</p>
119 </div><div class="long"><p>Returns the <a href="Ext.data.Model.html" rel="Ext.data.Model" class="docClass">Ext.data.Model</a> for a given model name</p>
120 <h3 class="pa">Parameters</h3><ul><li><span class="pre">id</span> : String/Object<div class="sub-desc"><p>The id of the model or the model instance.</p>
121 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
122 </li></ul></div></div></div><div id="method-isRegistered" class="member inherited"><a href="Ext.ModelManager.html#method-isRegistered" rel="method-isRegistered" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-isRegistered" class="viewSource">view source</a></div><a name="isRegistered"></a><a name="method-isRegistered"></a><a href="Ext.ModelManager.html#" rel="method-isRegistered" class="cls expand">isRegistered</a>(
123 <span class="pre">String type</span>)
124  : Boolean</div><div class="description"><div class="short"><p>Checks if an item type is registered.</p>
125 </div><div class="long"><p>Checks if an item type is registered.</p>
126 <h3 class="pa">Parameters</h3><ul><li><span class="pre">type</span> : String<div class="sub-desc"><p>The mnemonic string by which the class may be looked up</p>
127 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Boolean</span>&nbsp; &nbsp;<p>Whether the type is registered.</p>
128 </li></ul></div></div></div><div id="method-onAvailable" class="member inherited"><a href="Ext.ModelManager.html#method-onAvailable" rel="method-onAvailable" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-onAvailable" class="viewSource">view source</a></div><a name="onAvailable"></a><a name="method-onAvailable"></a><a href="Ext.ModelManager.html#" rel="method-onAvailable" class="cls expand">onAvailable</a>(
129 <span class="pre">String id, Function fn, Object scope</span>)
130  : void</div><div class="description"><div class="short">Registers a function that will be called when an item with the specified id is added to the manager. This will happen...</div><div class="long"><p>Registers a function that will be called when an item with the specified id is added to the manager. This will happen on instantiation.</p>
131 <h3 class="pa">Parameters</h3><ul><li><span class="pre">id</span> : String<div class="sub-desc"><p>The item id</p>
132 </div></li><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The callback function. Called with a single parameter, the item.</p>
133 </div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>The scope (<code>this</code> reference) in which the callback is executed. Defaults to the item.</p>
134 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
135 </li></ul></div></div></div><div id="method-register" class="member inherited"><a href="Ext.ModelManager.html#method-register" rel="method-register" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-register" class="viewSource">view source</a></div><a name="register"></a><a name="method-register"></a><a href="Ext.ModelManager.html#" rel="method-register" class="cls expand">register</a>(
136 <span class="pre">Mixed item</span>)
137  : void</div><div class="description"><div class="short"><p>Registers an item to be managed</p>
138 </div><div class="long"><p>Registers an item to be managed</p>
139 <h3 class="pa">Parameters</h3><ul><li><span class="pre">item</span> : Mixed<div class="sub-desc"><p>The item to register</p>
140 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
141 </li></ul></div></div></div><div id="method-registerType" class="member inherited"><a href="Ext.ModelManager.html#method-registerType" rel="method-registerType" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-registerType" class="viewSource">view source</a></div><a name="registerType"></a><a name="method-registerType"></a><a href="Ext.ModelManager.html#" rel="method-registerType" class="cls expand">registerType</a>(
142 <span class="pre">String type, Constructor cls</span>)
143  : void</div><div class="description"><div class="short"><p>Registers a new item constructor, keyed by a type key.
144
145 </div><div class="long"><p>Registers a new item constructor, keyed by a type key.
146
147 <h3 class="pa">Parameters</h3><ul><li><span class="pre">type</span> : String<div class="sub-desc"><p>The mnemonic string by which the class may be looked up.</p>
148 </div></li><li><span class="pre">cls</span> : Constructor<div class="sub-desc"><p>The new instance class.</p>
149 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
150 </li></ul></div></div></div><div id="method-unregister" class="member inherited"><a href="Ext.ModelManager.html#method-unregister" rel="method-unregister" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.AbstractManager.html" class="definedIn docClass">Ext.AbstractManager</a><br/><a href="../source/AbstractManager.html#Ext-AbstractManager-method-unregister" class="viewSource">view source</a></div><a name="unregister"></a><a name="method-unregister"></a><a href="Ext.ModelManager.html#" rel="method-unregister" class="cls expand">unregister</a>(
151 <span class="pre">Mixed item</span>)
152  : void</div><div class="description"><div class="short"><p>Unregisters an item by removing it from this manager</p>
153 </div><div class="long"><p>Unregisters an item by removing it from this manager</p>
154 <h3 class="pa">Parameters</h3><ul><li><span class="pre">item</span> : Mixed<div class="sub-desc"><p>The item to unregister</p>
155 </div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">void</span>&nbsp; &nbsp;
156 </li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>