为什么我的jsp页面不会显示ng-repeat中angularjs列表中的所有对象?

时间:2017-02-12 07:50:22

标签: javascript angularjs jsp

JSP

<table class="countrys" data-name="tableProductsBuy">
        <tr bgcolor="lightgrey">
            <th>Product ID</th>
            <th>Product Name</th>
            <th>In Store</th>
        </tr>
        <tr data-ng-repeat="p in finalList"
        data-ng-click="selectObject(p, $index);"
            data-ng-class="getSelectedObject(p);">
            <td>{{p.product.productId}}</td>
            <td>{{p.product.productName}}</td>
            <td>{{p.unitsOutStore}}</td>
        </tr>
    </table>    
    <button data-ng-click="buyIt()">Add to Shopping Cart</button>

控制器

$scope.getSelectedObject = function(object) {

    if ($scope.selectedObject.product.productId != undefined) {
        if ($scope.selectedObject.product.productId == object.product.productId) {
            return "selected";
        }
    }
    return "";
};


$scope.selectObject = function(object, index){
    $scope.selectedObject = object; 
}

$scope.finalList = [];
$scope.theListB = [];
$scope.counter = 0;
$scope.priceOfProducts = 0;
$scope.buyIt = function(){
    if ($scope.selectedProduct.unitsInStore>0){
        $scope.selectedProduct.unitsInStore--;
        $scope.theListB.push($scope.selectedProduct);
        $scope.priceOfProducts += $scope.selectedProduct.pricePerUnit;
    }else{
        alert("The product ID:" + $scope.selectedProduct.productId +"\n" +
                "With the name:"  + $scope.selectedProduct.productName + "\n"
                +"Is out of stock!");
    }

    $scope.showList();
}

$scope.showList=function(){
    $scope.finalList = [];

    angular.forEach($scope.theListB, function(productFromListB, key){
        var go = true;
        angular.forEach($scope.allSProducts, function(productFromStores, key){
            if(productFromListB.productId == productFromStores.productId){
            //  if(go){
                $scope.object.product = productFromListB;
                $scope.object.unitsOutStore = productFromStores.unitsInStore - productFromListB.unitsInStore;
                $scope.object.maxNumber = productFromStores.unitsInStore;
                $scope.finalList.push($scope.object);
                go = false;
            //  }
            }
        });  
    });
}

所以最后,我得到了函数$ scope.showList() 我有我的10个或更多对象提交的ListB 我修改的数据并使用以下行添加到finalList:

  $scope.finalList.push($scope.object);

但是在jsp页面上,它只显示表格行中最后添加的对象 在ng-repeat ...

任何sugestions?

这是一张图片

enter image description here

0 个答案:

没有答案