vue 查找数组对象中是否存在某个值

当表格数据中的角色列表包含超级管理员时,删除按钮会被设置为灰色并禁用。代码示例展示了如何在ElemeUI的表格组件中实现这一功能,通过遍历角色列表并使用some方法检查是否存在超级管理员,动态地给删除按钮添加class和禁用属性。
摘要由CSDN通过智能技术生成

列表角色包含‘超级管理员’时删除按钮置灰

//this.tableData=[{createTime:"2021-08-10 16:17:18",roleList: [{roleId: "2071802768015679540", roleName: "测试角色"}, {roleId: "2062895985096130886", roleName: "超级管理员"}]}]
 
<el-table :data="tableData" style="width: 100%">
          
                <el-table-column label="所属角色" min-width="160" show-overflow-tooltip>
                  <template slot-scope="scope">
                    <span v-for="(item, index) in scope.row.roleList" :key="index">{{
                      scope.row.roleList.length - 1 !== index ? item.roleName + ',' : item.roleName
                    }}</span>
                  </template>
                </el-table-column>
               
                <el-table-column label="操作" width="118" fixed="right">
                  <template slot-scope="scope">
                  //blue-text为蓝色字体样式,disabled-text为灰色字体样式
                    <el-button
                      type="text"
                      :class="scope.row.roleList.some(item => item.roleName =='超级管理员')?'disabled-text':'blue-text'"
                      :disabled="scope.row.roleList.some(item => item.roleName =='超级管理员')"
                      @click="handleDelete(scope.$index, scope.row)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
             
              </el-table>

效果图:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值