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 7079833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:43:13+00:00 2026-05-28T06:43:13+00:00

When I call fetch on my collection the app is calling the server and

  • 0

When I call fetch on my collection the app is calling the server and server returns an array of object. In the success function of the fetch call I’ve got an empty collection and the original response holding all objects that was responded by the server.

Collection

var OpenOrders = BaseCollection.extend({
    model: Order,
    url: baseUrl + '/api/orders?status=1'
});

Model

var Order = BaseModel.extend(

    {
        url:baseUrl + "/api/order",
        defaults:{
            order_items: new OrderList(),
            location: 1,
            remark: "remark"
        },

        initialize: function(options) {

            var orderItems = this.get('order_items');
            if (orderItems instanceof Array) {
                orderItems = new OrderList(orderItems);
                this.set({'order_items': orderItems})
            }
            orderItems.bind('change', _.bind(function() {
                this.trigger('change')
            }, this))
                .bind('remove', _.bind(function() {
                this.trigger('change')
            }, this));
            return this;
        },

    sum: function() {
        return  this.get('order_items').sum();
    },

    validate: function() {
        return !!this.get('order_items').length;
    },

    add:function(product) {
        this.get('order_items').add(product);

    },
    remove: function(product) {
        this.get('order_items').remove(product);

    }
);

Fetching the collection

this.collection.fetch({success:_.bind( function(collection, response){
            console.log('OpenOrdersListView', collection.toJSON())
            // logs []
            console.log('OpenOrdersListView', response)
            // logs [Object, Object ...]

        }, this)})
  • 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-05-28T06:43:14+00:00Added an answer on May 28, 2026 at 6:43 am

    Damm, its the validate method in my model. I’ve though validate have to return a boolean, but after reading the docs, it has to return an error message only if the model is not valid.

     validate: function() {
             if (!this.get('order_items').length){
                 return 'set minium of one product before save the order'
             }
        },
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I understand we can do something like this: Collection.fetch({success: function() { bla.. }
So I have a List collection that I fetch via a API call (which
Is it possible to have a MySQLi prepared statement within the fetch() call of
I call my JavaScript function. Why do I sometimes get the error 'myFunction is
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
I call the following function with a mouseover event but it's not working. My
Does urllib2 fetch the whole page when a urlopen call is made? I'd like
I'm trying to have a collection in backbone that calls /search/:searchTerm to the server
When I create a new collection, fetch is called automatically once. This gives me
In my backbone.js app, there is a Trips collection that holds Trip models ,

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.