Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     this.changedHandler = function(currentItem){
  2.         console.log("Categoryamount before:");
  3.         console.log(self.categoryAmount());
  4.         // Maak categoryAmount leeg
  5.         self.categoryAmount.removeAll();
  6.         // Vul category amount weer
  7.         for(var i = 0; i< self.cart().length; i++){
  8.             var currentCartItem = self.cart()[i];
  9.             // check if category already is in array
  10.             var existingCategory = ko.utils.arrayFirst(self.categoryAmount(), function(item) {
  11.             return currentCartItem.product().categoryId === item.categoryId();
  12.             });
  13.  
  14.             if(existingCategory !== null){
  15.                 existingCategory.amount(existingCategory.amount() + currentCartItem.amount);
  16.             }else{
  17.                 self.categoryAmount.push( new SelectedCategory(currentCartItem .product().categoryId, currentCartItem.amount));
  18.             }
  19.         }
  20.         console.log("Categoryamount after:");
  21.         console.log(self.categoryAmount());
  22.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement