Collections

AJAX Abstraction for Lists of Resources

models

The models property is an array of models representing the data for the collection.

Default Implementation

The default implementation looks like this:

models: []

Usage

Let's say you have an API endpoint located at http://localhost:1337/tweets, that returns a collection of tweets that looks like this:

[
  {
    id: 1,
    text: 'An old tweet'
  },
  {
    id: 2,
    text: 'A new tweet'
  }
]

If you wanted to retrieve those tweets, you could create this collection:

import { Collection } from 'lore-models';

const TweetCollection = Collection.extend({
  url: 'http://localhost:1337/tweets'
});

const tweets = new TweetCollection();

tweets.fetch();

Once the API call returns, tweet.models would look like this, where each resource from the API has been converted into a Model:

[
  new Model({
    id: 1,
    text: 'An old tweet'
  }),
  new Model({
    id: 2,
    text: 'A new tweet'
  })
]