在行和列的angularjs中创建动态复选框按钮

arg*_*rgs 2 javascript css checkbox button angularjs

请参阅此图片以进一步了解我的问题: 请访问此图片以进一步了解我的问题

我试图根据对象中提供的值在行和列中创建动态复选框按钮.

{"A":{"seats" : 10},"B":{"seats" : 8}}
Run Code Online (Sandbox Code Playgroud)

Far*_*naz 5

首先,您必须将此对象转换为数组,如下所示:

  $scope.array = [{ name: "A", seats: 10 }, { name: "B", seats: 8 }];
Run Code Online (Sandbox Code Playgroud)

然后,将数字转换为数组声明以下方法:

$scope.getNumber = function (num) {
    $scope.numbers = [];
    for (var i = 1; i < num+1 ; i++) {
        $scope.numbers.push(i);
    }
    return $scope.numbers;
}
Run Code Online (Sandbox Code Playgroud)

最后你应该ng-repeat输入你的HTML.

<div ng-repeat="item in array">
        <button type="button" ng-repeat="number in getNumber(item.seats)" ng-click="yourFunction()">
            {{item.name}}{{number}}
        </button>
</div>
Run Code Online (Sandbox Code Playgroud)

如果你有其他问题,请问我