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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:51:41+00:00 2026-06-01T10:51:41+00:00

Hi i have a collection and two views. On my view1 i’m adding data

  • 0

Hi i have a collection and two views. On my view1 i’m adding data to my collection and view2 will just render and display any changes about the collection. But i can’t get it to work. The problem is originally i’m doing this

return new CartCollection(); 

But they say its a bad practice so i remove changed it. But when i instantiate cart collection on view1 it would add but it seems view2 doesn’t sees the changes and renders nothing.

Any ideas?

here is my cart collection.

define([
 'underscore',
 'backbone',
 'model/cart'
], function(_, Backbone, CartModel) {
var CartCollection = Backbone.Collection.extend({
model : CartModel,
initialize: function(){
}
});
return CartCollection;
});

Here is my itemView ( view1 )

AddToCart:function(ev){
    ev.preventDefault();
    //get data-id of the current clicked item
    var id = $(ev.currentTarget).data("id");
    var item = this.collection.getByCid(id);
    var isDupe = false;
    //Check if CartCollection is empty then add
    if( CartCollection.length === 0){
        CartCollection.add([{ItemCode:item.get("ItemCode"),ItemDescription:item.get("ItemDescription"),SalesPriceRate:item.get("RetailPrice"),ExtPriceRate:item.get("RetailPrice"),WarehouseCode: "Main",ItemType : "Stock",LineNum:1 }]);
    }else{
        //if check if the item to be added is already added, if yes then update QuantityOrdered and ExtPriceRate
        _.each(CartCollection.models,function(cart){
            if(item.get("ItemCode") === cart.get("ItemCode")){
                isDupe = true;
                var updateQty = parseInt(cart.get("QuantityOrdered"))+1;
                var extPrice = parseFloat(cart.get("SalesPriceRate") * updateQty).toFixed(2);
                cart.set({ QuantityOrdered: updateQty });
                cart.set({ ExtPriceRate: extPrice });
            }
        });
        //if item to be added has no duplicates add new item
        if( isDupe == false){ 
            var cartCollection = CartCollection.at(CartCollection.length - 1);
            var lineNum = parseInt( cartCollection.get("LineNum") ) + 1;
            CartCollection.add([{ItemCode:item.get("ItemCode"),ItemDescription:item.get("ItemDescription"),SalesPriceRate:item.get("RetailPrice"),ExtPriceRate:item.get("RetailPrice"),WarehouseCode: "Main",ItemType : "Stock",LineNum:lineNum}]); 
            }
    }
    CartListView.render();
}

My cartview (view2)

render: function(){
  this.$("#cartContainer").html(CartListTemplate);
  var CartWrapper = kendobackboneModel(CartModel, {
     ItemCode: { type: "string" },
     ItemDescription: { type: "string" },
     RetailPrice: { type: "string" },
     Qty: { type: "string" },
  });
  var CartCollectionWrapper = kendobackboneCollection(CartWrapper);
  this.$("#grid").kendoGrid({
    editable: true,
    toolbar: [{ name: "save", text: "Complete" }],
    columns: [
        {field: "ItemDescription", title: "ItemDescription"},
        {field: "QuantityOrdered", title: "Qty",width:80},
        {field: "SalesPriceRate", title: "UnitPrice"},
        {field: "ExtPriceRate", title: "ExtPrice"}
    ],
    dataSource: {
      schema: {model: CartWrapper},
      data: new CartCollectionWrapper(CartCollection),
     }
  });

},
  • 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-01T10:51:42+00:00Added an answer on June 1, 2026 at 10:51 am

    The problem is you’ve created 2 different instances of CartCollection. So when you update or fetch data into one instance the other does not change but remains the same.

    Instead you need to use the same instance of CartCollection across the 2 views (or alternatively keep the 2 insync) .Assuming both views are in the same require.js module you would need to:

    1) Instantiate the CartCollection instance and store it somewhere that both views have access to. You could put this in the Router, the parent view, or anywhere else really.
    e.g.

    var router = Backbone.Router.extend({});
    router.carts = new CartCollection();
    

    2) You need need to pass the CartCollection instance to each of your views.
    e.g.

    var view1 = new ItemView({ collection: router.carts });
    var view2 = new CartView({ collection: router.carts });
    

    You may also want to just pass the Cart model to the CartView instead of the entire collection.
    e.g.

    var cartModel = router.carts.get(1);
    var view2 = new CartView({ model: cartModel });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two Model/Controllers which are essentially duplicating data (just on different pages). When
I have two Collection objects, I want to associate each object of these two
I have a Project Collection setup in my TFS2010RC deployment. I have two Projects
Can I contain two different types in a collection? For example, can I have
I have two ListViews in my app, with an initially identical collection of columns.
I have two views, one represents a view of clients and the other is
I have two ComboBoxes, A & B, each bound to an Observable Collection. Each
I'm learning mongodb and rails right now... I have two collection, User and Event
I have two views (JPanel) that uses the same domain object. My domain object
I have a database table that contains collection data for product collected from a

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.