Bonjour,

Je dois ajouter deux attributs qui n'existent pas dans l'objet JSON courant pour chaque "Produit". L'objet JSON des produits ressemble ci-dessous.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{
        "id": 1,
        "tempsTotal": 5000,
        "nbOperation": 3,
        "observations": "observations 1",
        "date": null,
        "produitId": 35,
        "listElementGamme": [
            {
                "id": 1,
                "temps": 20,
                "pdh": 30,
                "observations": "ob 1",
                "comptage": false,
                "operationId": 2,
                "gammeProduitId": 1,
                "sectionId": 1,
                "machineId": 1,
                "ordre": "1"
            },
            {
                "id": 2,
                "temps": 5,
                "pdh": 20,
                "observations": "ob 2",
                "comptage": true,
                "operationId": 3,
                "gammeProduitId": 1,
                "sectionId": 2,
                "machineId": 1,
                "ordre": "2"
            },
            {
                "id": 3,
                "temps": 6,
                "pdh": 9,
                "observations": "ob 3",
                "comptage": false,
                "operationId": 2,
                "gammeProduitId": 1,
                "sectionId": 2,
                "machineId": 2,
                "ordre": "3"
            }
        ]
    }
pour chaque produit je veux ajouter son code et sa désignation,lorsque je récupère "operationId" et je l'envoi vers un service pour récupérer le code et la désignation qui correspondent à chaque produit,l'objet JSON finale doit être comme ci-dessous:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{
    "id": 1,
    "tempsTotal": 5000,
    "nbOperation": 3,
    "observations": "observations 1",
    "date": null,
    "produitId": 35,
    "listElementGamme": [
        {
            "id": 1,
            "temps": 20,
            "pdh": 30,
            "observations": "ob 1",
            "comptage": false,
            "operationId": 2,
            "gammeProduitId": 1,
            "sectionId": 1,
            "machineId": 1,
            "ordre": "1",
            "code": "code 2",
            "designation": "designation 2"
        },
        {
            "id": 2,
            "temps": 5,
            "pdh": 20,
            "observations": "ob 2",
            "comptage": true,
            "operationId": 3,
            "gammeProduitId": 1,
            "sectionId": 2,
            "machineId": 1,
            "ordre": "2",
            "code": "code 3",
            "designation": "designation 3"
        },
        {
            "id": 3,
            "temps": 6,
            "pdh": 9,
            "observations": "ob 3",
            "comptage": false,
            "operationId": 7,
            "gammeProduitId": 1,
            "sectionId": 2,
            "machineId": 2,
            "ordre": "3",
            "code": "666",
            "designation": "TRRTR"
        }
    ]
}
mais ce que j'ai comme résultat est le suivant,dans toutes les lignes de tableau j'ai la dernière code "666" et designation "TRRTR":
Nom : re.png
Affichages : 2162
Taille : 16,9 Ko

je travaille avec angularJS,voici mon code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
$scope.modifierOuCreerArticle = function() {
                    var index = this.row.rowIndex;
 
                    $scope.finalOperationsList = [];
                    $http
                        .get("URL/getById:" +$scope.myData[index].id)
                        .success(
                            function(datagetArticle) {
 
 
                                $scope.finalOperationsList1 = datagetArticle.listElementGamme;
                                console.log("$scope.finalOperationsList1 :" +JSON.stringify($scope.finalOperationsList1));
 
                                var v = new Array();
 
 
                                for(i=0;i<$scope.finalOperationsList1.length;i++)
                                {
                                v[i] = $scope.finalOperationsList1[i].operationId;
 
 
 
                                gammeMonatageFactory.getListOperationsById(v[i])
                                    .then(
                                        function(
                                            Data) {
 
                                            code = Data.code;
                                            designation = Data.designation;
                                            console.log("$scope.liste :" +code+" "+designation); //I get the corect code/Designation of every operationId
 
                                            $scope.finalOperationsList = $scope.finalOperationsList1;
                                            console.log("$scope.finalOperationsList avant [j]:" +JSON.stringify($scope.finalOperationsList));
 
 
                                             for(var j=0;j<$scope.finalOperationsList1.length;j++)
                                            {
 
                                            $scope.finalOperationsList[j].code=code;
                                            $scope.finalOperationsList[j].designation=designation;
 
                                            }
 
                                             console.log("$scope.finalOperationsList aprs:" +JSON.stringify($scope.finalOperationsList));
 
                                        });
 
                                }
                                $scope.myData[index].listElementGamme = $scope.finalOperationsList;
                                console.log("$scope.myData[index].listElementGamme :" +JSON.stringify($scope.myData[index].listElementGamme));
                            });}
 
.......
   //the factory to get code/Designation of each Product
            .factory('gammeMonatageFactory', function($http,$q){
         var backObject = { getListOperationsById:_getListOperationsById }
         return backObject;
 
         function _getListOperationsById(val){ 
//this function is to call the code and designation for each operationId in "Products"         
                  var defer = $q.defer();
                  $http({
                      method : "GET",
                      url : "MyURL_to_get_operations_list/getById:"+val
                  }).then(function mySucces(response) {
                      defer.resolve(response.data);
                  }, function myError(response) {
 
                  });  return defer.promise;};   });
et voici mon code HTML:
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<tbody ui-sortable ng-model="finalOperationsList">
  <tr ng-repeat="item in finalOperationsList track by $index" style="cursor: move;">
     <td>{{item.ordre}}</td>                                           
     <td ng-model="item.code/></td>
     <td ng-model="item.designation"></td>
     <td ng-model="item.temps"></td>
     <td ng-model="item.pdh"></td>
     <td ><select ui-select2 ng-model="item.sectionId">
       <option ng-repeat="pi in listSections" value="{{pi.id}}">{{pi.designation}}</option>
      </select>
     </td>
     <td><select ui-select2 ng-model="item.machineId">
      <option ng-repeat="pi in listeMachines" value="{{pi.id}}">{{pi.designation}}</option>
     </select>
     </td>
     <td ng-model="item.observations" ></td>
  </tr>
</tbody>

je pense que le problème est au niveau de ma boucle "for",s'il vous plaît comment je peux corriger mon code,pour afficher dans le tableau le correcte code/Designation de chaque produit

merci pour l'aide