【问题标题】:Empty Message Is not showing in empty table in ng-repeat angularjs空消息未显示在 ng-repeat angularjs 的空表中
【发布时间】:2017-04-25 03:22:58
【问题描述】:

空文本未显示在表格中 我正在使用表 现在是空的

<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>ID</th>
            <th>Privilege Name</th>
            <th>PageUrl</th>
            <th>Can Add</th>
            <th>Can Edit</th>
            <th>Can Delete</th>
            <th>Can View</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="obj in getAssignedPrivilegeslist" ng-show="getAssignedPrivilegeslist.length !=0 && getAssignedPrivilegeslist !='null'">
            <td>{{$index+1}}</td>
            <td>{{obj.PageName}}</td>
            <td><a ng-href="{{'//'+obj.PageUrl }}">{{obj.PageUrl}}</a></td>
            <td>
                <input type="checkbox" name="Add" value="Add" ng-model="obj.CanCreate" />
            </td>
            <td>
                <input type="checkbox" name="Edit" value="Edit" ng-model="obj.CanEdit" />
            </td>
            <td>
                <input type="checkbox" name="Delete" value="Delete" ng-model="obj.CanDelete" />
            </td>
            <td>
                <input type="checkbox" name="View" value="View" ng-model="obj.CanView" />
            </td>
            <td ng-show="getAssignedPrivilegeslist.length==0" id="nofoundop">Please Select Operator</td>
        </tr>
    </tbody>
</table>

然后我设置一个&lt;td&gt; 如果数据长度为 0 然后显示给定的消息但它没有显示。 请帮助我将非常感谢你们。

【问题讨论】:

  • 仅供参考,ng-show="getAssignedPrivilegeslist.length !=0 &amp;&amp; getAssignedPrivilegeslist !='null'" 最好写成ng-show="getAssignedPrivilegeslist.length"。如果列表的长度是除 0 以外的任何数字,它将评估为 true,如果它为 0 或无法访问(因为它未定义),它将评估为 false。但是,如果您实际上将字符串文字 'null' 存储为它的值,则会遇到问题,因此如果您是,请将其更改为 null

标签: javascript jquery html angularjs html-table


【解决方案1】:

您必须在代码中进行这三项更改:

  • 您可以使用ng-show="getAssignedPrivilegeslist.length" 而不是ng-show="getAssignedPrivilegeslist.length !=0"。正如Harris Weinstein 在他的评论中所建议的那样,如果列表的长度是 0 以外的任何数字,它将评估为 true,如果它为 0 或无法访问(因为它未定义),它将评估为 false。

  • 不要使用字符串文字getAssignedPrivilegeslist !='null',而是使用getAssignedPrivilegeslist !=null

  • 将有错误消息的元素放在&lt;tr&gt; 之外,因为您已经将ng-show="getAssignedPrivilegeslist.length !=0" 放在&lt;tr&gt; 标记中。

您可以按照sexta13 的建议在&lt;tr&gt; 标记之外使用这样的方式:

<tr ng-show="getAssignedPrivilegeslist.length==0" >
   <td id="nofoundop">
      please select operator
   </td>
</tr>

【讨论】:

    【解决方案2】:

    你的逻辑结构不太好。

    你有你的

    <td ng-show="getAssignedPrivilegeslist.length==0" id="nofoundop">
        Please Select Operator
    </td>
    

    只有在 getAssignedPrivilegeslist.length !=0 && getAssignedPrivilegeslist !='null' 时才会发生的 ng-repeat 内

    您应该在 ng-repeat 之外有另一个 tr,如下所示:

    <tr ng-show="getAssignedPrivilegeslist.length==0" >
       <td id="nofoundop">
          please select operator
       </td>
    </tr>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 2014-11-10
      • 2018-01-17
      • 2016-12-10
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      相关资源
      最近更新 更多