Search code examples
javascriptbackbone.jsmarionette

Backbone/Marionette - How to fetch collection data from an external server?


Is there a similar property to urlRoot for a collection? My collection is currently set up as so:

Entities.Notifications = Entities.Collection.extend({
    model: Entities.Notification,
    url: '/notifications'
});

/notification is appended to the domain name when fetching. How do I do something like:

Entities.Notifications = Entities.Collection.extend({
    model: Entities.Notification,
    url: 'https://www.differentdomain.com/notifications'
});

So it gets the data from a different source?


Solution

  • Based on the example from the docs, it looks like if you define URL as a function it shouldn't do the append, something like:

    var Notes = Backbone.Collection.extend({
       url: function() {
          return 'https://www.differentdomain.com/notifications';
       }
    });