Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9003079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:40:05+00:00 2026-06-16T00:40:05+00:00

I have some global parameters that I want to be sent in every time

  • 0

I have some global parameters that I want to be sent in every time I call a fetch on a collection… my issue is I don’t want to declare the data: { ... } every time I fetch.

Is there a way I can provide default parameters inside the Collection itself with the possibility to add more or override some?

For example:

Instead of doing this every time:

this.articlesCollection.fetch({
    dataType: 'jsonp',
    data: {
        deviceType: GlobalVars.deviceType,
        memberId: GlobalVars.memberId,
        authToken: GlobalVars.authToken,
        targetObjectId: userId,
        limit: 50,
        excludeArticleBodies: true,
        excludeViewedItems: false
    },
    success: function() {
        _this.render();
    }
});

I’d like to just provide a one or two parameters and a success function, like this:

this.articlesCollection.fetch({
    data: {
        targetObjectId: userId
    },
    success: function() {
        _this.render();
    }
});

… and have the Collection look something like:

define([
  'underscore',
  'backbone',
  'global',
  'utilities',
  'models/article/ArticleModel'
], function(_, Backbone, GlobalVars, Utils, ArticleModel){

  var ArticlesCollection = Backbone.Collection.extend({

      model: ArticleModel,

      initialize : function(view) {
          this.view = view;
      },

      dataType: 'jsonp',
      data: {
          deviceType: GlobalVars.deviceType,
          memberId: GlobalVars.memberId,
          authToken: GlobalVars.authToken,
          limit: 50,
          excludeArticleBodies: true,
          excludeViewedItems: false
       },

      url : function() {
        return GlobalVars.baseAPIUrl + '/API/GetArticles';
      },

      parse : function(data) {  
        return data.Articles;
      }     

  });

  return ArticlesCollection;

});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:40:06+00:00Added an answer on June 16, 2026 at 12:40 am

    Here’s a working jsFiddle with one approach: http://jsfiddle.net/LEuGq/1/

    Basically, you configure both an object of defaultParams and params as properties of your collection, which are used to dynamically compute the correct URL when fetch() is called. This way is probably more in alignment with backbone than changing the API of fetch() to accept parameters, which it is not designed to do.

    var ParamCollection = Backbone.Collection.extend({
    
        defaultParams: {deviceType: 'raceCar', limit: 42},
        params: {},
        url: function() {
          return "/paramcollection?" + $.param(_.defaults(this.params, this.defaultParams));
        }
    });
    var paramCollection = new ParamCollection();
    paramCollection.params.excludeArticleBodies = true;
    paramCollection.params.limit = 52;
    $("#debug").append(paramCollection.url());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some code that I don't have control over is overriding the global JSON object
I have code in global.asax that sets some things in cache with CacheItemRemovedCallback. When
I have some arbitrary pixel data that I want to save as a PNG.
I have a question about global.asax that I don't really understand. My scenario is
I have a global JSON variable where I store some parameters and then each
I have some settings in my app.config which I intend to be 'global' -
For some reason I have to access Jenkins global environment variables like BUILD ID,
I have a global pointer variable char* pointer = new char[500]; /* some operations...
I have a huge global array of structures. Some regions of the array are
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.