AngularJs - 根据顶行选择禁用表上的输入

时间:2015-10-31 01:31:48

标签: angularjs html-table

如果在顶行上将“Active”或“Engaged”布尔值设置为true,我试图从顶部(主)行下方禁用表输入元素。当他们将数据设置为true时,我不希望他们将数据丢失在顶行之下,只是为了禁用它。如果用户设置“活动”&&在顶行“订婚”为假,然后我希望他们能够再次编辑顶行下方的数据。使用AngularJs有一种简单的方法吗?

以下是一个示例:https://jsfiddle.net/7kg6kuzm/2/

<body ng-app="test" ng-controller="AppCtrl">
<p>{{test}}</p>
<table class="table table-bordered">
    <thead>
        <tr>
            <th class="border-less"></th>
            <th>People</th>
            <th>Active</th>
            <th>Engaged</th>
            <th>Town</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="(month, info) in months">
            <td><p>{{month}}</p></td>
            <td><input type="text" ng-model="info.people"/></td>
            <td><input type="checkbox" ng-model="info.active"/></td>
            <td><input type="checkbox" ng-model="info.engaged"/></td>
            <td><input type="text" ng-model="info.form" /></td>
        </tr>
    </tbody>

可能的json对象值(在这种情况下,因为“all”或top行将其中一个布尔值设置为true,其余行将被禁用):

var months = {
  "all": {"people":25,"active":true,"engaged":false,"form":"test0"},
  "jan": {"people":63,"active":false,"engaged":true,"form":"test2"},
  "feb": {"people":46,"active":true,"engaged":false,"form":"test3"},
  "mar": {"people":65,"active":false,"engaged":false,"form":"test4"},
  "apr": {"people":66,"active":true,"engaged":true,"form":"test5"},
  "may": {"people":67,"active":false,"engaged":true,"form":"test6"}
}

1 个答案:

答案 0 :(得分:0)

我想出来了,以备将来参考,或者是否有其他人需要知道如何做到这一点:

https://jsfiddle.net/7kg6kuzm/3/

我最终检查了每条输入线,并检查了第一行的值:

<td><input ng-disabled="(months['all'].active || months['all'].engaged) && this.month!=='all'" type="text" ng-model="info.people"/></td>