【问题标题】:How to compare the value in ng-repeat in angularjs如何在angularjs中比较ng-repeat中的值
【发布时间】:2016-12-19 21:57:58
【问题描述】:

我正在使用 ng-repeat 获取数据并将其填充到表格中,这是我的表格

<table class="table table-bordered table-hover">
   <thead>
      <tr>
         <th>
            Sr. no.
         </th>
         <th>
            Title
         </th>
         <th>
            Image
         </th>
         <th>
            Category
         </th>
         <th>
            PostedOn
         </th>
         <th>
            Created By
         </th>
         <th>
            Status
         </th>
         <th>
            Active Blog
         </th>
      </tr>
   </thead>
   <tbody>
      <tr ng-repeat="obj in PostedBlogList | filter:searchText" ng-show="PostedBlogList.length">
         <td>{{$index+1}}</td>
         <td><a ng-href="{{'//'+obj.PageUrl }}">{{obj.Title}}</a></td>
         <td>
            <img style="width:90px" ng-show="obj.Image" src="{{obj.Image}}">
            <img style="width:90px" ng-show="!obj.Image" src="/images/mail.png">
         </td>
         <td>
            {{obj.CategoryName}}
         </td>
         <td>
            {{obj.CreatedDate}}
         </td>
         <td>
            {{obj.FirstName}}({{obj.UserType}})
         </td>
         <td>
            {{obj.IsActive}}
         </td>
         <td>
            <button class="btn btn-primary waves-effect waves-light" ng-click="ToActiveBlog(obj.Id)" ng-bind="btnactivate" type="submit" value="Activate"></button>
         </td>
      </tr>
      <tr ng-show="PostedBlogList.length==0">
      </tr>
   </tbody>
</table>

在状态行我得到状态true{{obj.IsActive}}

那么我如何检查{{obj.IsActive}} 如果它是真的然后设置“批准” 如果{{obj.IsActive}} 为假,则设置值“Pending”。

【问题讨论】:

    标签: javascript jquery angularjs html-table


    【解决方案1】:

    像这样使用三元运算符很棘手

     <td>
       {{obj.IsActive ? 'Approved ' : 'Pending'}}
     </td>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 2017-02-20
      相关资源
      最近更新 更多