2016-04-12 30 views
0

Angularjs ile yeni yaşıyorum. Bu problemi aldım. Birkaç sorularda bulduk ama kimse bana lütfen yardımcı olabilir benimle Mentionned ama hiç iş olarak $ endeksine göre parça kullanılmış çünkü kimse benim için faydalı oldu

html: burada

<table> 
       <tbody> 
        <tr class="main-heading"> 
         <th>Images</th> 
         <th class="long-txt">Product Description</th> 
         <th>Numero de serie</th> 
         <th>Price</th> 
         <th>Total</th> 
        </tr> 
        <tr class="cake-bottom" data-ng-repeat="product in chosenPdtByQte track by $index"> 
         <td class="cakes"> 
          <div class="product-img2"></div> 
         </td> 
         <td class="cake-text"> 
          <div class="product-text"> 
           <h3>{{product.nameProduct}}</h3> 
           <p>Product Code: {{product.numserie}}</p> 
          </div> 
         </td> 
         <td ng-init="fetchNumSerie(product.id)"> 
         <select name="singleSelect" ng-model="selecteOperation" ng-options="pdt as pdt.id for pdt in numSeries" > 
       </select> 



         </td> 

         <td> 
          <h4>{{product.price}}</h4> 
         </td> 

         <td class="top-remove"> 
          <h4>{{product.price*quantite[product.id]}}</h4> 
          <div class="close-btm"> 
           <h5>Remove</h5> 
          </div> 
         </td> 
        </tr> 
       </tbody> 
      </table> 

Ve is my Ben

for (var i =0; i< $scope.chosenProducts.length; i++) 
          { 
          console.log(" lllll "+$scope.chosenProducts[i].quantite +" "+$scope.quantite[$scope.chosenProducts[i].id]); 
          for (var j=0; j<$scope.quantite[$scope.chosenProducts[i].id]; j++) 
           { 

           $scope.chosenPdtByQte.push($scope.chosenProducts[i]); 

          } 
          } 
+0

Soruna neden "ng-repeat" olduğundan emin misiniz? 'ng-options 'aynı yineleyiciye izin verilmez' hatalarını atacaktır, yani 'numSeries''in benzersiz olduğunu iki kez kontrol etmelisiniz. – Scott

+0

Eminim ng-options bile kullanmadan önce bu problemi alıyorum çünkü – yeddez

+0

Neler olup bittiğini görmek için bir keman veya benzer bir şey sağlayabilir misiniz? –

cevap

0

deneyin listemi fulling ediyorum kontrolör track by product.id kullanmak.

<tr class="cake-bottom" 
data-ng-repeat="product in chosenPdtByQte track by product.id"> 
...... 
</tr> 
+0

Her zaman aynı sorunu yaşıyorsanız: / – yeddez

0

bu şekilde kullanarak ve üzerinde ng tekrarı uygulamak deneyin bir liste oluşturduk Gerçekten neden bilmiyorum, ama ben şu kod çiftleri sorunsuz iyi çalışıyor tahmin

angular.module("myApp", []) 
 
    .controller("myCtrl", function($scope) { 
 
    $scope.chosenProducts = [{ 
 
     "id": 1, 
 
     "nameProduct": "testA", 
 
     "numserie": "xx-ff-gg-ss", 
 
     "price": 20 
 
    }, { 
 
     "id": 2, 
 
     "nameProduct": "testB", 
 
     "numserie": "yy-ee-gg-ss", 
 
     "price": 30 
 
    }, { 
 
     "id": 3, 
 
     "nameProduct": "testC", 
 
     "numserie": "xx-ss-gg-ss", 
 
     "price": 40 
 
    }, { 
 
     "id": 4, 
 
     "nameProduct": "testD", 
 
     "numserie": "xx-ff-ff-ss", 
 
     "price": 50 
 
    }, { 
 
     "id": 5, 
 
     "nameProduct": "testE", 
 
     "numserie": "xx-ff-11-ss", 
 
     "price": 60 
 
    }, { 
 
     "id": 6, 
 
     "nameProduct": "testF", 
 
     "numserie": "xx-ff-dd-ss", 
 
     "price": 70 
 
    }]; 
 

 
    $scope.quantite = [ 
 
     4, 5, 6, 7, 8, 9 
 
    ]; 
 

 
    $scope.chosenPdtByQte = []; 
 

 
    for (var i = 0; i < $scope.chosenProducts.length; i++) { 
 
     for (var j = 0; j < $scope.quantite[$scope.chosenProducts[i].id]; j++) { 
 
     $scope.chosenPdtByQte.push($scope.chosenProducts[i]); 
 
     } 
 
    } 
 
    console.log($scope.chosenPdtByQte); 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 

 
<div ng-app="myApp" ng-controller="myCtrl"> 
 
    <table> 
 
    <tbody> 
 
     <tr class="main-heading"> 
 
     <th>Images</th> 
 
     <th class="long-txt">Product Description</th> 
 
     <th>Numero de serie</th> 
 
     <th>Price</th> 
 
     <th>Total</th> 
 
     </tr> 
 
     <tr class="cake-bottom" data-ng-repeat="product in chosenPdtByQte track by $index"> 
 
     <td class="cakes"> 
 
      <div class="product-img2"></div> 
 
     </td> 
 
     <td class="cake-text"> 
 
      <div class="product-text"> 
 
      <h3>{{product.nameProduct}}</h3> 
 
      <p>Product Code: {{product.numserie}}</p> 
 
      </div> 
 
     </td> 
 
     <td ng-init="fetchNumSerie(product.id)"> 
 
      <select name="singleSelect" ng-model="selecteOperation" ng-options="pdt as pdt.id for pdt in numSeries"> 
 
      </select> 
 
     </td> 
 

 
     <td> 
 
      <h4>{{product.price}}</h4> 
 
     </td> 
 

 
     <td class="top-remove"> 
 
      <h4>{{product.price*quantite[product.id]}}</h4> 
 
      <div class="close-btm"> 
 
      <h5>Remove</h5> 
 
      </div> 
 
     </td> 
 
     </tr> 
 
    </tbody> 
 
    </table> 
 
</div>

İlgili konular