Hello,

I have a cart and every time a user adds a item to the cart, trough http it 
sends data to the php rest API where i store the data in the db. in every 
cart_rule there is a column called addons wich is a array (in php) so when 
i save it, i save it as a Json array in the db so that angular can handle 
it:

    $item['addons'] = json_encode($addonsShow);


Now in angular i do a ng-repeat like so:

    <div ng-repeat="cartitem in $root.cart" style="border-bottom:1px solid 
#dedede">
      <div style="float:left;width:17%;font-size:17px;">
          <i class="fa fa-plus-square" ng-click=
"qtyUp('{{cartitem.cart_rule_id}}','{{$root.sessionid}}')"><B><span style="
font-size:11px">&nbsp;{{cartitem.qty}}</span></B></i>
          <i class="fa fa-minus-square" ng-click=
"qtyDown('{{cartitem.cart_rule_id}}','{{$root.sessionid}}')"></i>
          {{cartitem.menu_item_name}} 
           
            <!--
            <div ng-repeat="as in cartAddonsShow(cartitem.addons) traqck by 
$index">
            {{as.a_addonname}}
            </div>
            -->


      </div>
    </div>


because cartItem.addons is a array/object i have to do another ng repeat in 
the first one.. loop in loop. Now at first i could not just loop over 
`cartitem.addons` because for some strange reason the json_encode data that 
is in it, is seen as a string like this:

    addons: "[{"a_addonid":"32","a_addongroupid":"20","a_addonname":"rrrrr
","a_priceoption":"paid","a_price":"2.00","addongroupid":"20","optiontype":"
single","groupname":"bij asdad"}]"


so i made a method to convert this to a "array" 
`"cartAddonsShow(cartitem.addons)"` wich looks like this:

    $scope.cartAddonsShow = function(data) {
      var x = angular.fromJson(data);
      console.log(x);
      return x;
    };


now my console log shows this:

    [Object]
    0: Object
    a_addongroupid: "20"
    a_addonid: "34"
    a_addonname: "sdfsdfsfwwwwww"
    a_price: "0.00"
    a_priceoption: "free"
    addongroupid: "20"
    groupname: "Deze alleen bij asdad"optiontype: "single"
    __proto__: Objectlength: 1
    __proto__: Array[0] main.js:269
    [Object] main.js:269
    [Object] main.js:269
    [Object] main.js:269
    [Object] main.js:269
    [Object] main.js:269


the first object is colapsed. THis is good, now im getting the data as a 
proper object. The strange thing is that i get it 6 times? why is this?

all the 6 objects are the same one... So in my ng-repeat i see everything 6 
times... and when there are more addons i see it more times.... what is 
happening here ?

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to