ampersand-collection
Advanced tools
Comparing version 1.6.0 to 1.6.1
{ | ||
"name": "ampersand-collection", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -225,3 +225,30 @@ # ampersand-collection | ||
### parse `collection.parse(data, [options])` | ||
The parse method gets called if the `{parse: true}` option is passed when calling `collection.set` method. By default, `parse` simply returns the data it was passed, but can be overwritten through `.extend` to provide any additional parsing logic to extract the array of data that should be stored in the collection. This is most commonly used when processing data coming back from an ajax request. The response from an API may look like this: | ||
```javascript | ||
{ | ||
"limit": 100, | ||
"offset": 0, | ||
"data": [ | ||
{"name": "larry"}, | ||
{"name": "curly"}, | ||
{"name": "moe"} | ||
] | ||
} | ||
``` | ||
To extract `data` you'd define a `parse` method on the collection as follows, to return the array of data to be stored. | ||
```javascript | ||
var MyCollection = Collection.extend({ | ||
parse: function (response) { | ||
return response.data; | ||
} | ||
}); | ||
``` | ||
If you're using `ampersand-rest-collection`'s `fetch()` method, the `parse` method will be called with the response by default. Also, the options object passed to `set()` gets passed through as a second argument to allow for conditional parsing logic. | ||
### set `collection.set(models, [options])` | ||
@@ -228,0 +255,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33304
392