Push rows in a table rendered with ng-repeat in angular

前端 未结 3 2026
忘了有多久
忘了有多久 2021-02-03 11:31

I want to push in an extra row inline in a table when the client clicks on the row. The data should not be prefetched, since I expect there to be at most 30 rows but where each

3条回答
  •  悲&欢浪女
    2021-02-03 12:15

    One sample

    var app = angular.module('test-app', []);
    
    app.controller('MyController', function($scope, $rootScope, $timeout){
    
        $scope.copy = {
            p1: ['c1 p1', 'c1 p2'],
            p3: ['c3 p1', 'c3 p2', 'c3 p3', 'c3 p4', 'c3 p5']
        }
    
        $scope.courts = [
            {
                "number": 1,
                "name": "the best court",
                "nrOfPlayers": 2
            }, {
                "number": 2,
                "name": "the bad court",
                "nrOfPlayers": 0
            }, {
                "number": 3,
                "name": "the other court",
                "nrOfPlayers": 5
            }
        ];
    
        $scope.loadPlayers = function(court){
            //Implement your logic here
            //Probably using ajax
            $timeout(function(){
                $scope.players = $scope.copy['p' + court.number] || [];
            }, Math.random() * 2000);
        }
    
        $scope.shouDetails = function(court){
            if(court.nrOfPlayers) {
                delete $scope.players;
                $scope.loadPlayers(court);
            } else {
                $scope.players = [];
            }
        }
    
    })
    

    Demo: Fiddle

提交回复
热议问题