Angularjs 如何为启用的特定选定行设置按钮?

Angularjs 如何为启用的特定选定行设置按钮?,angularjs,Angularjs,有一个HTML表格,其中我为每一行添加SET按钮:- <table cellpadding="0" cellspacing="0"> <thead> <tr> <th>Row1</th> <th>Row2</th> <th>Row3</th> <th>Row4

有一个HTML表格,其中我为每一行添加SET按钮:-

<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>Row1</th>
            <th>Row2</th>
            <th>Row3</th>
            <th>Row4</th>
            <th>Row5</th>
            <th>Row6</th>
            <th>Row7</th>
            <th>Row8</th>
            <th>Row9</th>
            <th>Row10</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in array track by $index" ng-class="{'selected': isSelected(row.value1)}" ng-click="selectRow(row.value1)">
            <td>{{row.value1}}</td>
            <td>{{row.value2}}</td>
            <td>{{row.value3}}</td>
            <td>{{row.value4}}</td>
            <td>{{row.value5}}</td>
            <td>{{row.value6}}</td>
            <td>{{row.value7}}</td>
            <td>{{row.value8}}</td>
            <td>{{row.value9}}</td>
            <td>{{row.value10}}</td>
            <td><button type="button" ng-disabled = "setBtnDisable" 
           class="btn btn-xs btn-primary" data-ng-click="show()">SET</button></td>
        </tr>
    </tbody>
</table>

我想做的是,仅为特定选定行启用SET按钮,其余行的SET按钮保持禁用状态。但是现在当我点击任何一行时,所有的按钮都被启用了。有人能告诉我只为select行启用SET按钮的解决方案吗?

代码中的一切似乎都很好,因为您在按钮中使用了一个变量来设置ng disabled,当设置为true时,它将应用于所有表行

<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>Row1</th>
            <th>Row2</th>
            <th>Row3</th>
            <th>Row4</th>
            <th>Row5</th>
            <th>Row6</th>
            <th>Row7</th>
            <th>Row8</th>
            <th>Row9</th>
            <th>Row10</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in array track by $index" ng-class="{'selected': isSelected(row.value1)}" ng-click="selectRow(row.value1)">
            <td>{{row.value1}}</td>
            <td>{{row.value2}}</td>
            <td>{{row.value3}}</td>
            <td>{{row.value4}}</td>
            <td>{{row.value5}}</td>
            <td>{{row.value6}}</td>
            <td>{{row.value7}}</td>
            <td>{{row.value8}}</td>
            <td>{{row.value9}}</td>
            <td>{{row.value10}}</td>
            <td><button type="button" ng-disabled = "setBtnDisable" 
           class="btn btn-xs btn-primary" data-ng-click="show()">SET</button></td>
        </tr>
    </tbody>
</table>
解决方案:

<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>Row1</th>
            <th>Row2</th>
            <th>Row3</th>
            <th>Row4</th>
            <th>Row5</th>
            <th>Row6</th>
            <th>Row7</th>
            <th>Row8</th>
            <th>Row9</th>
            <th>Row10</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in array track by $index" ng-class="{'selected': isSelected(row.value1)}" ng-click="selectRow(row.value1)">
            <td>{{row.value1}}</td>
            <td>{{row.value2}}</td>
            <td>{{row.value3}}</td>
            <td>{{row.value4}}</td>
            <td>{{row.value5}}</td>
            <td>{{row.value6}}</td>
            <td>{{row.value7}}</td>
            <td>{{row.value8}}</td>
            <td>{{row.value9}}</td>
            <td>{{row.value10}}</td>
            <td><button type="button" ng-disabled = "setBtnDisable" 
           class="btn btn-xs btn-primary" data-ng-click="show()">SET</button></td>
        </tr>
    </tbody>
</table>
对禁用的ng使用相同的函数,但反转布尔值。因此,它对于每一行都是唯一的,您将获得所需的结果!像这样

<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>Row1</th>
            <th>Row2</th>
            <th>Row3</th>
            <th>Row4</th>
            <th>Row5</th>
            <th>Row6</th>
            <th>Row7</th>
            <th>Row8</th>
            <th>Row9</th>
            <th>Row10</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in array track by $index" ng-class="{'selected': isSelected(row.value1)}" ng-click="selectRow(row.value1)">
            <td>{{row.value1}}</td>
            <td>{{row.value2}}</td>
            <td>{{row.value3}}</td>
            <td>{{row.value4}}</td>
            <td>{{row.value5}}</td>
            <td>{{row.value6}}</td>
            <td>{{row.value7}}</td>
            <td>{{row.value8}}</td>
            <td>{{row.value9}}</td>
            <td>{{row.value10}}</td>
            <td><button type="button" ng-disabled = "setBtnDisable" 
           class="btn btn-xs btn-primary" data-ng-click="show()">SET</button></td>
        </tr>
    </tbody>
</table>
<button type="button" ng-disabled="!isSelected(row.value1)" 
class="btn btn-xs btn-primary" data-ng-click="show()">SET</button>

嗨,你的问题我认为是挫折,因为这是你所有行的问题

<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>Row1</th>
            <th>Row2</th>
            <th>Row3</th>
            <th>Row4</th>
            <th>Row5</th>
            <th>Row6</th>
            <th>Row7</th>
            <th>Row8</th>
            <th>Row9</th>
            <th>Row10</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in array track by $index" ng-class="{'selected': isSelected(row.value1)}" ng-click="selectRow(row.value1)">
            <td>{{row.value1}}</td>
            <td>{{row.value2}}</td>
            <td>{{row.value3}}</td>
            <td>{{row.value4}}</td>
            <td>{{row.value5}}</td>
            <td>{{row.value6}}</td>
            <td>{{row.value7}}</td>
            <td>{{row.value8}}</td>
            <td>{{row.value9}}</td>
            <td>{{row.value10}}</td>
            <td><button type="button" ng-disabled = "setBtnDisable" 
           class="btn btn-xs btn-primary" data-ng-click="show()">SET</button></td>
        </tr>
    </tbody>
</table>
如果您尝试以下方法会怎么样:

<table cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th>Row1</th>
            <th>Row2</th>
            <th>Row3</th>
            <th>Row4</th>
            <th>Row5</th>
            <th>Row6</th>
            <th>Row7</th>
            <th>Row8</th>
            <th>Row9</th>
            <th>Row10</th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="row in array track by $index" ng-class="{'selected': isSelected(row.value1)}" ng-click="selectRow(row.value1)">
            <td>{{row.value1}}</td>
            <td>{{row.value2}}</td>
            <td>{{row.value3}}</td>
            <td>{{row.value4}}</td>
            <td>{{row.value5}}</td>
            <td>{{row.value6}}</td>
            <td>{{row.value7}}</td>
            <td>{{row.value8}}</td>
            <td>{{row.value9}}</td>
            <td>{{row.value10}}</td>
            <td><button type="button" ng-disabled = "setBtnDisable" 
           class="btn btn-xs btn-primary" data-ng-click="show()">SET</button></td>
        </tr>
    </tbody>
</table>
    scope.setBtnDisable = [array.length];
scope.setBtnDisable.forEach(function(item){
item = false;
});
    scope.selectedRow = null;//Default value

                scope.selectRow = function(rowID){

                        scope.setBtnDisable[rowID] = !scope.setBtnDisable[rowID] ;
                        scope.selectedRow = null;

                };

                scope.isSelected = function(rowID){
                    return (scope.selectedRow == rowID);
                };