vue v-for中使用filter筛选数据

遍历的时候筛选IsUse为true的数据,我这么写问题在哪?为什么加上以后页面上一条数据都没有,去掉filter就有数据了
图片描述

加上filter

 <tr v-for="(item,index) in roadList.filter(obj=>{obj.IsUse==true})" :key="index">
              <td>{{item.RouteName}}</td>
              <td>{{item.CodeType}}</td>
              <td>{{item.PointCodeStartId}}</td>
              <td>{{item.CodeFirStart}}</td>
              <td>{{item.CodeIcaoStart}}</td>
              <td>{{item.PointCodeEndId}}</td>
              <td>{{item.CodeFirEnd}}</td>
              <td>{{item.CodeIcaoEnd }}</td>
              <td>{{item.DirecDescription}}</td>
</tr>

图片描述

去掉filter

 <tr v-for="(item,index) in roadList" :key="index">
              <td>{{item.RouteName}}</td>
              <td>{{item.CodeType}}</td>
              <td>{{item.PointCodeStartId}}</td>
              <td>{{item.CodeFirStart}}</td>
              <td>{{item.CodeIcaoStart}}</td>
              <td>{{item.PointCodeEndId}}</td>
              <td>{{item.CodeFirEnd}}</td>
              <td>{{item.CodeIcaoEnd }}</td>
              <td>{{item.DirecDescription}}</td>
</tr>

图片描述

阅读 17.1k
4 个回答

filter 是需要你把符合标准的规则return回去的...
上面写的 roadList.filter(obj => {return obj.IsUse === true})
roadList.filter(obj => obj.IsUse === true)
都可以解决问题

.filter(obj=>obj.IsUse==true) 括号去掉试试

这种写法可以优化的:roadList.filter(obj=>{obj.IsUse}) obj.IsUse存在则为保留。

let roadList=[{IsUse:true},{IsUse:false}]
//chrome里这样返回的结果是对的
roadList.filter(obj=>{return obj.IsUse})

图片描述

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题