javascript - 获取数组变量react元素的位置
问题描述
我试图根据我的卷轴的位置来获得一个城市。
拍卖数据:
[{"id": -1}, {"User": {"_deleted": null, "_lastChangedAt": 1624758300151, "_version": 2, "createdAt": "2021-06-27T01:44:00.636Z", "id": "bbba1e58-64a4-4b8d-ae93-d60e14601461", "name": "Just in Time", "owner": null, "subscribers": "culpa adipisicin", "thumbnail": "excepteur occaecat volupt", "updatedAt": "2021-06-27T01:45:00.127Z"}, "_deleted": null, "_lastChangedAt": 1624853545493, "_version": 7, "city": "California", "country": "USA", "createdAt": "2021-06-27T03:30:03.710Z", "description": "ut adipisicing la", "dislikes": 25, "expiration": 30, "id": "d9e5be9f-21cd-4e09-82e9-e70bf4c51204", "likes": 24, "owner": null, "rating": 4, "thumbnail": "https://pretest.s3.amazonaws.com/CarChase.png", "title": "Auction 2", "updatedAt": "2021-06-28T04:12:25.466Z", "userID": null, "views": 17}, {"User": {"_deleted": null, "_lastChangedAt": 1624758300151, "_version": 2, "createdAt": "2021-06-27T01:44:00.636Z", "id": "bbba1e58-64a4-4b8d-ae93-d60e14601461", "name": "Just in Time", "owner": null, "subscribers": "culpa adipisicin", "thumbnail": "excepteur occaecat volupt", "updatedAt": "2021-06-27T01:45:00.127Z"}, "_deleted": null, "_lastChangedAt": 1624764983268, "_version": 8, "city": "Florida", "country": "USA", "createdAt": "2021-06-27T01:44:08.334Z", "description": "amet laborum officia sint ut m", "dislikes": 16, "expiration": 27, "id": "03c5504c-de2a-483d-8dc4-be4282a668e2", "likes": 30, "owner": null, "rating": 2, "thumbnail": "https://pretest.s3.amazonaws.com/CarChase.png", "title": "Auction 1", "updatedAt": "2021-06-27T03:36:23.244Z", "userID": "bbba1e58-64a4-4b8d-ae93-d60e14601461", "views": 29}, {"id": -2}]
代码
// Scroll - Primary
const mainScrollX = useRef(new Animated.Value(0)).current;
const city = { '0': 'California', '130': 'Florida' };
const groupCity = useMemo(
() => auction.filter((target) => target.city === city[130]),
[mainScrollX]
);
console.log('---');
console.log(mainScrollX);
console.log(groupCity);
console.log(city[0]);
console.log(city[130]);
console.log(city[mainScrollX]);
console.log('---');
我不确定是否需要在“mainScrollX”上进行转换,它在 0 时似乎有问题。
mainScrollX 为 0 或 130。
在 0 时,
LOG ---
LOG 0
LOG []
LOG California
LOG Florida
LOG undefined
LOG ---
在 130 岁时,
LOG ---
LOG 130
LOG []
LOG California
LOG Florida
LOG undefined
LOG ---
解决方案
推荐阅读
- python - 以确定的方式重塑张量
- javascript - 多系列折线图 d3v4 上的工具提示,d3.bisect 的问题
- visual-studio-code - 在 `nice` 下启动远程 VS Code
- google-bigquery - 使用多行数据透视 BigQuery 表
- python-3.x - PyQt5 交互后崩溃
- arrays - kotlin Firebase 变量路径
- python - 从 pandas.core.series.series 检索数据并将它们保存到矩阵中
- ssis - 如何将csv文件中的日期转换为整数
- r - 将多个列中的因子水平相加
- java - 创建对应不同宽度断点的不同虚拟设备