this.usersFromList = this.usersFromList.filter(e=>e.userId !== this.userId)这样写 为啥没有过略掉相等的
时间: 2024-04-19 07:29:58 浏览: 13
如果你将过滤代码写成 `this.usersFromList = this.usersFromList.filter(e=>e.userId !== this.userId)`,但没有达到你预期的过滤效果,可能有以下几个原因:
1. `this.userId` 的值可能不正确:请确保 `this.userId` 的值是你期望的,可以通过打印或调试来进行确认。
2. `this.usersFromList` 的值可能不是你期望的数组:请确保 `this.usersFromList` 是一个有效的数组,并且包含了 `userId` 属性。
3. 对象的属性名可能不正确:请确保对象中的属性名是准确的,大小写敏感,并且与你想要过滤的属性名一致。
如果你仔细检查了以上几点,并且确认没有问题,但仍然无法正确过滤,请提供更多相关代码和错误信息,以便我能够更好地帮助你解决问题。
相关问题
this.usersFromList = this.usersFromList.filter(user => user.userId !== this.userId);这样写没有过略掉
如果你的代码 `this.usersFromList = this.usersFromList.filter(user => user.userId !== this.userId);` 没有正确过滤掉相等的项,可能有以下几个原因:
1. `this.userId` 的值可能不正确:请确保 `this.userId` 的值是你期望的,可以通过打印或调试来进行确认。
2. `this.usersFromList` 的值可能不是你期望的数组:请确保 `this.usersFromList` 是一个有效的数组,并且包含了 `userId` 属性。
3. 对象的属性名可能不正确:请确保对象中的属性名是准确的,大小写敏感,并且与你想要过滤的属性名一致。
如果你仔细检查了以上几点,并且确认没有问题,但仍然无法正确过滤,请提供更多相关代码和错误信息,以便我能够更好地帮助你解决问题。
vue 过略掉this.usersFromList中userId相等的
你可以使用 Vue 的计算属性和数组的 `filter` 方法来过滤掉 `this.usersFromList` 中 `userId` 相等的项。以下是一个示例代码:
```javascript
computed: {
filteredUsers() {
return this.usersFromList.filter(user => user.userId !== this.userId);
}
}
```
在这个示例中,`filteredUsers` 是一个计算属性,它返回一个过滤后的用户列表。`filter` 方法接受一个回调函数作为参数,该回调函数对数组中的每个元素进行判断,只有当 `userId` 不等于 `this.userId` 时才会保留该元素。
你可以在模板中使用 `filteredUsers` 属性来显示过滤后的用户列表。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)