backbone /docs/todos.html

Language HTML Lines 766
MD5 Hash 638bd84ab05c45b2e66bf327bf8d3fb5
Repository https://github.com/huangbaihua001/backbone.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
<!DOCTYPE html>

<html>
<head>
  <title>todos.js</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
  <link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
  <div id="container">
    <div id="background"></div>
    
      <ul id="jump_to">
        <li>
          <a class="large" href="javascript:void(0);">Jump To &hellip;</a>
          <a class="small" href="javascript:void(0);">+</a>
          <div id="jump_wrapper">
          <div id="jump_page">
            
              
              <a class="source" href="backbone.localstorage.html">
                backbone.localstorage.js
              </a>
            
              
              <a class="source" href="todos.html">
                todos.js
              </a>
            
          </div>
        </li>
      </ul>
    
    <ul class="sections">
        
          <li id="title">
              <div class="annotation">
                  <h1>todos.js</h1>
              </div>
          </li>
        
        
        
        <li id="section-1">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-1">&#182;</a>
              </div>
              <p>An example Backbone application contributed by
<a href="http://jgn.me/">J茅r么me Gravel-Niquet</a>. This demo uses a simple
<a href="backbone-localstorage.html">LocalStorage adapter</a>
to persist Backbone models within your browser.

</p>
<p>Load the application once the DOM is ready, using <code>jQuery.ready</code>:
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>$(<span class="keyword">function</span>(){</pre></div></div>
            
        </li>
        
        
        <li id="section-2">
            <div class="annotation">
              
              <div class="pilwrap for-h2">
                <a class="pilcrow" href="#section-2">&#182;</a>
              </div>
              <h2>Todo Model</h2>

            </div>
            
        </li>
        
        
        <li id="section-3">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-3">&#182;</a>
              </div>
              <p>Our basic <strong>Todo</strong> model has <code>title</code>, <code>order</code>, and <code>done</code> attributes.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">var</span> Todo = Backbone.Model.extend({</pre></div></div>
            
        </li>
        
        
        <li id="section-4">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-4">&#182;</a>
              </div>
              <p>Default attributes for the todo item.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    defaults: <span class="keyword">function</span>() {
      <span class="keyword">return</span> {
        title: <span class="string">"empty todo..."</span>,
        order: Todos.nextOrder(),
        done: <span class="literal">false</span>
      };
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-5">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-5">&#182;</a>
              </div>
              <p>Toggle the <code>done</code> state of this todo item.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    toggle: <span class="keyword">function</span>() {
      <span class="keyword">this</span>.save({done: !<span class="keyword">this</span>.get(<span class="string">"done"</span>)});
    }

  });</pre></div></div>
            
        </li>
        
        
        <li id="section-6">
            <div class="annotation">
              
              <div class="pilwrap for-h2">
                <a class="pilcrow" href="#section-6">&#182;</a>
              </div>
              <h2>Todo Collection</h2>

            </div>
            
        </li>
        
        
        <li id="section-7">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-7">&#182;</a>
              </div>
              <p>The collection of todos is backed by <em>localStorage</em> instead of a remote
server.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">var</span> TodoList = Backbone.Collection.extend({</pre></div></div>
            
        </li>
        
        
        <li id="section-8">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-8">&#182;</a>
              </div>
              <p>Reference to this collection&#39;s model.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    model: Todo,</pre></div></div>
            
        </li>
        
        
        <li id="section-9">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-9">&#182;</a>
              </div>
              <p>Save all of the todo items under the <code>&quot;todos-backbone&quot;</code> namespace.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    localStorage: <span class="keyword">new</span> Backbone.LocalStorage(<span class="string">"todos-backbone"</span>),</pre></div></div>
            
        </li>
        
        
        <li id="section-10">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-10">&#182;</a>
              </div>
              <p>Filter down the list of all todo items that are finished.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    done: <span class="keyword">function</span>() {
      <span class="keyword">return</span> <span class="keyword">this</span>.where({done: <span class="literal">true</span>});
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-11">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-11">&#182;</a>
              </div>
              <p>Filter down the list to only todo items that are still not finished.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    remaining: <span class="keyword">function</span>() {
      <span class="keyword">return</span> <span class="keyword">this</span>.without.apply(<span class="keyword">this</span>, <span class="keyword">this</span>.done());
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-12">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-12">&#182;</a>
              </div>
              <p>We keep the Todos in sequential order, despite being saved by unordered
GUID in the database. This generates the next order number for new items.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    nextOrder: <span class="keyword">function</span>() {
      <span class="keyword">if</span> (!<span class="keyword">this</span>.length) <span class="keyword">return</span> <span class="number">1</span>;
      <span class="keyword">return</span> <span class="keyword">this</span>.last().get(<span class="string">'order'</span>) + <span class="number">1</span>;
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-13">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-13">&#182;</a>
              </div>
              <p>Todos are sorted by their original insertion order.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    comparator: <span class="string">'order'</span>

  });</pre></div></div>
            
        </li>
        
        
        <li id="section-14">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-14">&#182;</a>
              </div>
              <p>Create our global collection of <strong>Todos</strong>.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">var</span> Todos = <span class="keyword">new</span> TodoList;</pre></div></div>
            
        </li>
        
        
        <li id="section-15">
            <div class="annotation">
              
              <div class="pilwrap for-h2">
                <a class="pilcrow" href="#section-15">&#182;</a>
              </div>
              <h2>Todo Item View</h2>

            </div>
            
        </li>
        
        
        <li id="section-16">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-16">&#182;</a>
              </div>
              <p>The DOM element for a todo item...
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">var</span> TodoView = Backbone.View.extend({</pre></div></div>
            
        </li>
        
        
        <li id="section-17">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-17">&#182;</a>
              </div>
              <p>... is a list tag.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    tagName:  <span class="string">"li"</span>,</pre></div></div>
            
        </li>
        
        
        <li id="section-18">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-18">&#182;</a>
              </div>
              <p>Cache the template function for a single item.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    template: _.template($(<span class="string">'#item-template'</span>).html()),</pre></div></div>
            
        </li>
        
        
        <li id="section-19">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-19">&#182;</a>
              </div>
              <p>The DOM events specific to an item.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    events: {
      <span class="string">"click .toggle"</span>   : <span class="string">"toggleDone"</span>,
      <span class="string">"dblclick .view"</span>  : <span class="string">"edit"</span>,
      <span class="string">"click a.destroy"</span> : <span class="string">"clear"</span>,
      <span class="string">"keypress .edit"</span>  : <span class="string">"updateOnEnter"</span>,
      <span class="string">"blur .edit"</span>      : <span class="string">"close"</span>
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-20">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-20">&#182;</a>
              </div>
              <p>The TodoView listens for changes to its model, re-rendering. Since there&#39;s
a one-to-one correspondence between a <strong>Todo</strong> and a <strong>TodoView</strong> in this
app, we set a direct reference on the model for convenience.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    initialize: <span class="keyword">function</span>() {
      <span class="keyword">this</span>.listenTo(<span class="keyword">this</span>.model, <span class="string">'change'</span>, <span class="keyword">this</span>.render);
      <span class="keyword">this</span>.listenTo(<span class="keyword">this</span>.model, <span class="string">'destroy'</span>, <span class="keyword">this</span>.remove);
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-21">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-21">&#182;</a>
              </div>
              <p>Re-render the titles of the todo item.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    render: <span class="keyword">function</span>() {
      <span class="keyword">this</span>.$el.html(<span class="keyword">this</span>.template(<span class="keyword">this</span>.model.toJSON()));
      <span class="keyword">this</span>.$el.toggleClass(<span class="string">'done'</span>, <span class="keyword">this</span>.model.get(<span class="string">'done'</span>));
      <span class="keyword">this</span>.input = <span class="keyword">this</span>.$(<span class="string">'.edit'</span>);
      <span class="keyword">return</span> <span class="keyword">this</span>;
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-22">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-22">&#182;</a>
              </div>
              <p>Toggle the <code>&quot;done&quot;</code> state of the model.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    toggleDone: <span class="keyword">function</span>() {
      <span class="keyword">this</span>.model.toggle();
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-23">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-23">&#182;</a>
              </div>
              <p>Switch this view into <code>&quot;editing&quot;</code> mode, displaying the input field.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    edit: <span class="keyword">function</span>() {
      <span class="keyword">this</span>.$el.addClass(<span class="string">"editing"</span>);
      <span class="keyword">this</span>.input.focus();
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-24">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-24">&#182;</a>
              </div>
              <p>Close the <code>&quot;editing&quot;</code> mode, saving changes to the todo.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    close: <span class="keyword">function</span>() {
      <span class="keyword">var</span> value = <span class="keyword">this</span>.input.val();
      <span class="keyword">if</span> (!value) {
        <span class="keyword">this</span>.clear();
      } <span class="keyword">else</span> {
        <span class="keyword">this</span>.model.save({title: value});
        <span class="keyword">this</span>.$el.removeClass(<span class="string">"editing"</span>);
      }
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-25">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-25">&#182;</a>
              </div>
              <p>If you hit <code>enter</code>, we&#39;re through editing the item.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    updateOnEnter: <span class="keyword">function</span>(e) {
      <span class="keyword">if</span> (e.keyCode == <span class="number">13</span>) <span class="keyword">this</span>.close();
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-26">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-26">&#182;</a>
              </div>
              <p>Remove the item, destroy the model.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    clear: <span class="keyword">function</span>() {
      <span class="keyword">this</span>.model.destroy();
    }

  });</pre></div></div>
            
        </li>
        
        
        <li id="section-27">
            <div class="annotation">
              
              <div class="pilwrap for-h2">
                <a class="pilcrow" href="#section-27">&#182;</a>
              </div>
              <h2>The Application</h2>

            </div>
            
        </li>
        
        
        <li id="section-28">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-28">&#182;</a>
              </div>
              <p>Our overall <strong>AppView</strong> is the top-level piece of UI.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">var</span> AppView = Backbone.View.extend({</pre></div></div>
            
        </li>
        
        
        <li id="section-29">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-29">&#182;</a>
              </div>
              <p>Instead of generating a new element, bind to the existing skeleton of
the App already present in the HTML.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    el: $(<span class="string">"#todoapp"</span>),</pre></div></div>
            
        </li>
        
        
        <li id="section-30">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-30">&#182;</a>
              </div>
              <p>Our template for the line of statistics at the bottom of the app.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    statsTemplate: _.template($(<span class="string">'#stats-template'</span>).html()),</pre></div></div>
            
        </li>
        
        
        <li id="section-31">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-31">&#182;</a>
              </div>
              <p>Delegated events for creating new items, and clearing completed ones.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    events: {
      <span class="string">"keypress #new-todo"</span>:  <span class="string">"createOnEnter"</span>,
      <span class="string">"click #clear-completed"</span>: <span class="string">"clearCompleted"</span>,
      <span class="string">"click #toggle-all"</span>: <span class="string">"toggleAllComplete"</span>
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-32">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-32">&#182;</a>
              </div>
              <p>At initialization we bind to the relevant events on the <code>Todos</code>
collection, when items are added or changed. Kick things off by
loading any preexisting todos that might be saved in <em>localStorage</em>.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    initialize: <span class="keyword">function</span>() {

      <span class="keyword">this</span>.input = <span class="keyword">this</span>.$(<span class="string">"#new-todo"</span>);
      <span class="keyword">this</span>.allCheckbox = <span class="keyword">this</span>.$(<span class="string">"#toggle-all"</span>)[<span class="number">0</span>];

      <span class="keyword">this</span>.listenTo(Todos, <span class="string">'add'</span>, <span class="keyword">this</span>.addOne);
      <span class="keyword">this</span>.listenTo(Todos, <span class="string">'reset'</span>, <span class="keyword">this</span>.addAll);
      <span class="keyword">this</span>.listenTo(Todos, <span class="string">'all'</span>, <span class="keyword">this</span>.render);

      <span class="keyword">this</span>.footer = <span class="keyword">this</span>.$(<span class="string">'footer'</span>);
      <span class="keyword">this</span>.main = $(<span class="string">'#main'</span>);

      Todos.fetch();
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-33">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-33">&#182;</a>
              </div>
              <p>Re-rendering the App just means refreshing the statistics -- the rest
of the app doesn&#39;t change.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    render: <span class="keyword">function</span>() {
      <span class="keyword">var</span> done = Todos.done().length;
      <span class="keyword">var</span> remaining = Todos.remaining().length;

      <span class="keyword">if</span> (Todos.length) {
        <span class="keyword">this</span>.main.show();
        <span class="keyword">this</span>.footer.show();
        <span class="keyword">this</span>.footer.html(<span class="keyword">this</span>.statsTemplate({done: done, remaining: remaining}));
      } <span class="keyword">else</span> {
        <span class="keyword">this</span>.main.hide();
        <span class="keyword">this</span>.footer.hide();
      }

      <span class="keyword">this</span>.allCheckbox.checked = !remaining;
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-34">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-34">&#182;</a>
              </div>
              <p>Add a single todo item to the list by creating a view for it, and
appending its element to the <code>&lt;ul&gt;</code>.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    addOne: <span class="keyword">function</span>(todo) {
      <span class="keyword">var</span> view = <span class="keyword">new</span> TodoView({model: todo});
      <span class="keyword">this</span>.$(<span class="string">"#todo-list"</span>).append(view.render().el);
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-35">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-35">&#182;</a>
              </div>
              <p>Add all items in the <strong>Todos</strong> collection at once.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    addAll: <span class="keyword">function</span>() {
      Todos.each(<span class="keyword">this</span>.addOne, <span class="keyword">this</span>);
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-36">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-36">&#182;</a>
              </div>
              <p>If you hit return in the main input field, create new <strong>Todo</strong> model,
persisting it to <em>localStorage</em>.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    createOnEnter: <span class="keyword">function</span>(e) {
      <span class="keyword">if</span> (e.keyCode != <span class="number">13</span>) <span class="keyword">return</span>;
      <span class="keyword">if</span> (!<span class="keyword">this</span>.input.val()) <span class="keyword">return</span>;

      Todos.create({title: <span class="keyword">this</span>.input.val()});
      <span class="keyword">this</span>.input.val(<span class="string">''</span>);
    },</pre></div></div>
            
        </li>
        
        
        <li id="section-37">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-37">&#182;</a>
              </div>
              <p>Clear all done todo items, destroying their models.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>    clearCompleted: <span class="keyword">function</span>() {
      _.invoke(Todos.done(), <span class="string">'destroy'</span>);
      <span class="keyword">return</span> <span class="literal">false</span>;
    },

    toggleAllComplete: <span class="function"><span class="keyword">function</span> <span class="params">()</span> {</span>
      <span class="keyword">var</span> done = <span class="keyword">this</span>.allCheckbox.checked;
      Todos.each(<span class="function"><span class="keyword">function</span> <span class="params">(todo)</span> {</span> todo.save({<span class="string">'done'</span>: done}); });
    }

  });</pre></div></div>
            
        </li>
        
        
        <li id="section-38">
            <div class="annotation">
              
              <div class="pilwrap ">
                <a class="pilcrow" href="#section-38">&#182;</a>
              </div>
              <p>Finally, we kick things off by creating the <strong>App</strong>.
</p>

            </div>
            
            <div class="content"><div class='highlight'><pre>  <span class="keyword">var</span> App = <span class="keyword">new</span> AppView;

});</pre></div></div>
            
        </li>
        
    </ul>
  </div>
</body>
</html>
Back to Top