You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/chapters/collection.md
+25-9Lines changed: 25 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Collection
2
2
3
-
Collections are ordered sets of records. You can bind "changes" events to be notified when the collection has been modified, listen for "add" and "remove" events, fetch the collection from the server, and use a full suite of iteration methods.
3
+
Collections are ordered sets of records. You can bind "changes" events to be notified when the collection has been modified, listen for the record "add", "remove", and "change" events, and use a full suite of iteration methods.
4
4
5
5
```javascript
6
6
// Implicitly defined collection.
@@ -51,27 +51,37 @@ Specify the record type inside of the collection's definition. This property is
51
51
52
52
## Create and dispose
53
53
54
-
### new Collection()
54
+
### new Collection( records?, options? )
55
55
56
-
Create an empty collection.
57
-
58
-
### new Collection( records, options? )
56
+
Create an aggregating serializable collection of records. The collection will take an ownership on its records and will put an error in the console if it can't.
59
57
60
58
When creating a Collection, you may choose to pass in the initial array of records. The collection's comparator may be included as an option. Passing `false` as the comparator option will prevent sorting. If you define an `initialize() ` function, it will be invoked when the collection is created.
61
59
62
60
```javascript
63
61
var tabs =newTabSet([tab1, tab2, tab3]);
64
62
```
65
63
66
-
### collection.initialize( records?, options? )
64
+
### new Collection.Refs( records?, options? )
67
65
68
-
Initialization function which is called at the end of the constructor.
66
+
Create a non-aggregating non-serializable collection. The collection does not take ownership in its records. In all other aspects it behaves as the regular collection.
69
67
70
-
### collection.dispose()
68
+
### collection.createSubset( records?, options? )
69
+
70
+
Create a non-aggregating serializable collection which is the subset of the given collection. Takes the same arguments as the collection's constructor.
71
+
72
+
<asideclass="notice">Records in the collection must have an `id` attribute populated to work properly with subsets.</aside>
Synchronize the state of the collection and its aggregation tree with other collection of the same type. Updates existing objects in place. Record in the collection is considered to be "existing" if it has the same `id`.
209
+
210
+
Equivalent to `collection.set( otherCollection.models, { merge : true } )` and triggers similar events on change.
211
+
196
212
### collection.reset( records, options? )
197
213
198
214
Replace the collection's content with the new records. More efficient than `collection.set`, but does not send record-level events.
<p>Recursively traverse aggregation tree errors. <code>key</code> is <code>null</code> for the record-level validation error (returned from <code>validate()</code>).
825
825
<code>recordOrCollection</code> is the reference to the current object.</p>
826
826
<h1id="collection">Collection</h1>
827
-
<p>Collections are ordered sets of records. You can bind "changes" events to be notified when the collection has been modified, listen for "add" and "remove" events, fetch the collection from the server, and use a full suite of iteration methods.</p>
827
+
<p>Collections are ordered sets of records. You can bind "changes" events to be notified when the collection has been modified, listen for the record "add", "remove", and "change" events, and use a full suite of iteration methods.</p>
828
828
<pre><codeclass="highlight javascript"><spanclass="hljs-comment">// Implicitly defined collection.</span>
<p>Create an aggregating serializable collection of records. The collection will take an ownership on its records and will put an error in the console if it can't.</p>
867
866
<p>When creating a Collection, you may choose to pass in the initial array of records. The collection's comparator may be included as an option. Passing <code>false</code> as the comparator option will prevent sorting. If you define an <code>initialize()</code> function, it will be invoked when the collection is created.</p>
<p>Create a non-aggregating non-serializable collection. The collection does not take ownership in its records. In all other aspects it behaves as the regular collection.</p>
<p>Create a non-aggregating serializable collection which is the subset of the given collection. Takes the same arguments as the collection's constructor.</p>
873
+
<asideclass="notice">Records in the collection must have an `id` attribute populated to work properly with subsets.</aside>
<p>Synchronize the state of the collection and its aggregation tree with other collection of the same type. Updates existing objects in place. Record in the collection is considered to be "existing" if it has the same <code>id</code>.</p>
975
+
<p>Equivalent to <code>collection.set( otherCollection.models, { merge : true } )</code> and triggers similar events on change.</p>
<p>Replace the collection's content with the new records. More efficient than <code>collection.set</code>, but does not send record-level events.</p>
969
978
<p>Calling <code>collection.reset()</code> without passing any records as arguments will empty the entire collection.</p>
0 commit comments