1
- ## Marionette.CollectionView
1
+ # Marionette.CollectionView
2
2
3
3
The ` CollectionView ` will loop through all of the models in the
4
4
specified collection, render each of them using a specified ` itemView ` ,
5
5
then append the results of the item view's ` el ` to the collection view's
6
6
` el ` .
7
7
8
- ### CollectionView's ` itemView `
8
+ ## CollectionView's ` itemView `
9
9
10
10
Specify an ` itemView ` in your collection view definition. This must be
11
11
a Backbone view object definition (not instance). It can be any
@@ -33,7 +33,7 @@ new MyCollectionView({
33
33
If you do not specify an ` itemView ` , an exception will be thrown
34
34
stating that you must specify an ` itemView ` .
35
35
36
- ### CollectionView's ` itemViewOptions `
36
+ ## CollectionView's ` itemViewOptions `
37
37
38
38
There may be scenarios where you need to pass data from your parent
39
39
collection view in to each of the itemView instances. To do this, provide
@@ -62,7 +62,7 @@ calculate the values to return at runtime. The function must return an
62
62
object, and the attributes of the object will be copied to the itemView
63
63
instance' options.
64
64
65
- ### CollectionView's ` emptyView `
65
+ ## CollectionView's ` emptyView `
66
66
67
67
When a collection has no items, and you need to render a view other than
68
68
the list of itemViews, you can specify an ` emptyView ` attribute on your
@@ -83,14 +83,14 @@ Backbone.Marionette.CollectionView.extend({
83
83
This will render the ` emptyView ` and display the message that needs to
84
84
be displayed when there are no items.
85
85
86
- ### Callback Methods
86
+ ## Callback Methods
87
87
88
88
There are several callback methods that can be provided on a
89
89
` CollectionView ` . If they are found, they will be called by the
90
90
view's base methods. These callback methods are intended to be
91
91
handled within the view definition directly.
92
92
93
- #### beforeRender callback
93
+ ### beforeRender callback
94
94
95
95
A ` beforeRender ` callback will be called just prior to rendering
96
96
the collection view.
@@ -103,7 +103,7 @@ Backbone.Marionette.CollectionView.extend({
103
103
});
104
104
```
105
105
106
- #### onRender callback
106
+ ### onRender callback
107
107
108
108
After the view has been rendered, a ` onRender ` method will be called.
109
109
You can implement this in your view to provide custom code for dealing
@@ -117,7 +117,7 @@ Backbone.Marionette.CollectionView.extend({
117
117
});
118
118
```
119
119
120
- #### onItemAdded callback
120
+ ### onItemAdded callback
121
121
122
122
This callback function allows you to know when an item / item view
123
123
instance has been added to the collection view. It provides access to
@@ -131,7 +131,7 @@ Backbone.Marionette.CollectionView.extend({
131
131
});
132
132
```
133
133
134
- #### beforeClose callback
134
+ ### beforeClose callback
135
135
136
136
This method is called just before closing the view.
137
137
@@ -143,7 +143,7 @@ Backbone.Marionette.CollectionView.extend({
143
143
});
144
144
```
145
145
146
- #### onClose callback
146
+ ### onClose callback
147
147
148
148
This method is called just after closing the view.
149
149
@@ -155,13 +155,13 @@ Backbone.Marionette.CollectionView.extend({
155
155
});
156
156
```
157
157
158
- ### CollectionView Events
158
+ ## CollectionView Events
159
159
160
160
There are several events that will be triggered during the life
161
161
of a collection view. These are intended to be handled from code
162
162
external to the view.
163
163
164
- #### "collection:before: render " event
164
+ ### "collection:before: render " event
165
165
166
166
Triggers just prior to the view being rendered
167
167
@@ -177,7 +177,7 @@ myView.on("collection:before:render", function(){
177
177
myView .render ();
178
178
```
179
179
180
- #### "render" / "collection: rendered " event
180
+ ### "render" / "collection: rendered " event
181
181
182
182
A "collection: rendered " event will also be fired. This allows you to
183
183
add more than one callback to execute after the view is rendered,
@@ -200,7 +200,7 @@ myView.on("collection:rendered", function(){
200
200
myView .render ();
201
201
```
202
202
203
- #### "collection:before: close " event
203
+ ### "collection:before: close " event
204
204
205
205
Triggered just before closing the view.
206
206
@@ -216,7 +216,7 @@ myView.on("collection:before:close", function(){
216
216
myView .close ();
217
217
```
218
218
219
- #### "collection: closed " event
219
+ ### "collection: closed " event
220
220
221
221
Triggered just after closing the view.
222
222
@@ -232,7 +232,7 @@ myView.on("collection:closed", function(){
232
232
myView .close ();
233
233
```
234
234
235
- #### "itemview:\* " event bubbling from child views
235
+ ### "itemview:\* " event bubbling from child views
236
236
237
237
When an item view within a collection view triggers an
238
238
event, that event will bubble up through the parent
@@ -275,7 +275,7 @@ Normally, you would have your item view listening to DOM
275
275
events or model change events, and then triggering an event
276
276
of it's own based on that.
277
277
278
- ### CollectionView render
278
+ ## CollectionView render
279
279
280
280
The ` render ` method of the collection view is responsible for
281
281
rendering the entire collection. It loops through each of the
@@ -290,7 +290,7 @@ new MyCollectionView().render().done(function(){
290
290
});
291
291
```
292
292
293
- ### CollectionView: Automatic Rendering
293
+ ## CollectionView: Automatic Rendering
294
294
295
295
The collection view binds to the "add", "remove" and "reset" events of the
296
296
collection that is specified.
@@ -304,13 +304,13 @@ one model in to the collection of item views.
304
304
When a model is removed from a collection (or destroyed / deleted), the collection
305
305
view will close and remove that model's item view.
306
306
307
- ### CollectionView: Re-render Collection
307
+ ## CollectionView: Re-render Collection
308
308
309
309
If you need to re-render the entire collection, you can call the
310
310
` view.render ` method. This method takes care of closing all of
311
311
the child views that may have previously been opened.
312
312
313
- ### CollectionView's appendHtml
313
+ ## CollectionView's appendHtml
314
314
315
315
By default the collection view will call jQuery's ` .append ` to
316
316
move the HTML contents from the item view instance in to the collection
@@ -332,7 +332,7 @@ The first parameter is the instance of the collection view that
332
332
will receive the HTML from the second parameter, the current item
333
333
view instance.
334
334
335
- ### CollectionView close
335
+ ## CollectionView close
336
336
337
337
CollectionView implements a ` close ` method, which is called by the
338
338
region managers automatically. As part of the implementation, the
0 commit comments