|
100 | 100 | });
|
101 | 101 |
|
102 | 102 | // We can retrieve a collection from the server
|
103 |
| - var cards = CreditCard.query(); |
104 |
| - // GET: /user/123/card |
105 |
| - // server returns: [ {id:456, number:'1234', name:'Smith'} ]; |
106 |
| -
|
107 |
| - var card = cards[0]; |
108 |
| - // each item is an instance of CreditCard |
109 |
| - expect(card instanceof CreditCard).toEqual(true); |
110 |
| - card.name = "J. Smith"; |
111 |
| - // non GET methods are mapped onto the instances |
112 |
| - card.$save(); |
113 |
| - // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'} |
114 |
| - // server returns: {id:456, number:'1234', name: 'J. Smith'}; |
115 |
| -
|
116 |
| - // our custom method is mapped as well. |
117 |
| - card.$charge({amount:9.99}); |
118 |
| - // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'} |
119 |
| - // server returns: {id:456, number:'1234', name: 'J. Smith'}; |
| 103 | + var cards = CreditCard.query(function() { |
| 104 | + // GET: /user/123/card |
| 105 | + // server returns: [ {id:456, number:'1234', name:'Smith'} ]; |
| 106 | +
|
| 107 | + var card = cards[0]; |
| 108 | + // each item is an instance of CreditCard |
| 109 | + expect(card instanceof CreditCard).toEqual(true); |
| 110 | + card.name = "J. Smith"; |
| 111 | + // non GET methods are mapped onto the instances |
| 112 | + card.$save(); |
| 113 | + // POST: /user/123/card/456 {id:456, number:'1234', name:'J. Smith'} |
| 114 | + // server returns: {id:456, number:'1234', name: 'J. Smith'}; |
| 115 | +
|
| 116 | + // our custom method is mapped as well. |
| 117 | + card.$charge({amount:9.99}); |
| 118 | + // POST: /user/123/card/456?amount=9.99&charge=true {id:456, number:'1234', name:'J. Smith'} |
| 119 | + }); |
120 | 120 |
|
121 | 121 | // we can create an instance as well
|
122 | 122 | var newCard = new CreditCard({number:'0123'});
|
|
0 commit comments