簡體   English   中英

AngularJs:基於第一列中的下拉菜單顯示/隱藏表列

[英]AngularJs: Show/Hide table column based on dropdown in first column

使用angularjs

我有一張表,我將其綁定到數組的第一列。

第二列是一個下拉列表。

我想根據第二列下拉菜單的值顯示/隱藏其他5-6列(文本和下拉列表)。

我嘗試了以下代碼:

  <table class="table table-bordered">
    <thead>
    <tr>
        <th>Name</th>
        <th>Value</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    <tr ng-repeat="item in items">
       <td >{{item.name}}</td>
       <td >  
          <select name="utype" class="form-control input-medium"  ng-model="utype">
                  <option value="">---Please select---</option>
                  <option ng-repeat="type in types" >{{type.text}}</option>
          </select></td>
      <td><span ng-hide="utype =='Type1' || utype!=undefined" >{{item.value}}</span></td>
      <td><button class="btn btn-small" ng-click="edit(item)">Edit</button></td>
    </tr>
    </tbody>
  </table>

ng-hide="utype =='Type1' || utype!=undefined"

但這僅是第一次。 隱藏后不起作用。

誰能指出我需要做些什么才能使其工作:

utype!=undefined設置ng-model="utype">后, utype!=undefined始終為true。 取出utype!=undefined嘗試一下。

<td><span ng-hide="utype =='Type1' >{{item.value}}</span></td>

另外,imo,您應該使用===而不是'=='。 有關詳細信息,請參見此SO答案
例如。 ng-hide="utype ==='Type1'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM