Ich bin wie im Code-Schnipsel, eine einfache HTML-Seite mitProbleme mit Abrufen von Daten aus verschachtelter ng-repeat
<!doctype html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller('MainController', ['$scope', function($scope){
$scope.products = ['Product1', 'Product2', 'Product3'];
$scope.Menu = {
Minimum: 10,
Maximum: 20,
Discount: 2.00
};
$scope.MenuList = [];
//$scope.MenuList.push($scope.Menu);
$scope.AddNode = function($index){
var arr = {
arrIndex: ($scope.MenuList.length + 1),
arrValue: $scope.Menu
};
$scope.MenuList.push(arr);
};
$scope.RemoveNode = function(){
$scope.MenuList.pop();
};
\t \t
\t \t $scope.SubmitQuery = function(){
\t \t \t $scope.ExpectedResult = $scope.MenuList;
\t \t };
}]);
</script>
</head>
<body ng-app="myApp">
<div ng-controller="MainController">
<table style="width: 60%;" border="0" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th rowspan="2">Sr. No</th>
<th rowspan="2">Product Name</th>
<th colspan="2">Quantities</th>
<th rowspan="2">Discount %</th>
<th rowspan="2">Manage</th>
<th rowspan="2">Submit</th>
</tr>
<tr>
<th>Min. Quantity</th>
<th>Max. Quantity</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="product in products">
<td>{{$index + 1}}</td>
<td>{{product}}</td>
<td colspan="3">
<table style="width: 100%;">
<tbody>
<tr ng-repeat="menu in MenuList">
<td>
<input type="text"/>
</td>
<td>
<input type="text"/>
</td>
<td>
<input type="text"/>
</td>
</tr>
</tbody>
</table>
</td>
<td>
<button ng-click="AddNode($index)">+</button>
<button ng-click="RemoveNode($index)">-</button>
</td>
<td>
<button ng-click="SubmitQuery()">Submit</button>
</td>
</tr>
</tbody>
</table>
\t <div>
\t \t {{ExpectedResult}}
\t </div>
</div>
</body>
</html>
Die Ausgabe von bestimmtem Code ist
[
{
"arrIndex":1,
"arrValue":{"Minimum":10,"Maximum":20,"Discount":2}},
{
"arrIndex":2,
"arrValue":{"Minimum":10,"Maximum":20,"Discount":2}
}
]
Die erwartete Ausgabe ist
[{
"Product1":
[
{
"arrIndex":1,
"arrValue":{"Minimum":10, "Maximum":20, "Discount":2}
},
{
"arrIndex":2,
"arrValue":{"Minimum":21, "Maximum":30, "Discount":2}
}
],
"Product2":
[
{
"arrIndex":1,
"arrValue":{"Minimum":50, "Maximum":60, "Discount":5}
},
{
"arrIndex":2,
"arrValue":{"Minimum":60, "Maximum":70, "Discount":5}
}
]
}]
Auch nach zwei Tagen der Analyse bin ich nicht in der Lage, die Winkelmodellbindung richtig zu bekommen, wenn ng-repeat verschachtelt ist. (Jede Ressource Referenz ist sehr zu begrüßen).
Ich muss nur die Ausgabe mit dem jeweiligen Produkt zuordnen.
Jungs bitte helfen, ich brauche es verzweifelt.
Vielen Dank. Haben Sie einen schönen Tag. :-)