我想包括这张幻灯片: https: //swiperjs.com/react/
由于我发现拖动下一张幻灯片不太舒服,因此我想onClick向完整滑块添加一个事件,以便下一张幻灯片出现。
如何slideNext()在 React 中触发 a ?我在阅读文档时遇到问题/我不理解它 - 并且文档似乎没有告诉如何在反应中执行此操作。
在 jquery 中,它会是这样的:
$('section.slideshow').on( 'click', function() {
swiper.slideNext();
});
Run Code Online (Sandbox Code Playgroud)
这是我的反应代码:
import React from 'react'
import SwiperCore, { Navigation, Pagination, A11y } from 'swiper'
import { Swiper, SwiperSlide } from 'swiper/react'
import 'swiper/swiper.scss'
import 'swiper/components/navigation/navigation.scss'
import 'swiper/components/pagination/pagination.scss'
SwiperCore.use([Navigation, Pagination, A11y])
function Page(){
return (
<div>
<Swiper
onClick={() => console.log('click')}
onTouchStart={() => slideNext() }
>
<SwiperSlide>slide 1</SwiperSlide>
<SwiperSlide>slide 2</SwiperSlide>
</Swiper>
</div>
);
}
export default Page;
Run Code Online (Sandbox Code Playgroud) 我有一个带有图像 ID 的字符串(从另一个 mysql 表中获取)并转换为数组:
$idstring = "12, 18, 3, 392, 0, 9, 44";
$idarray = explode(',', $idstring);
Run Code Online (Sandbox Code Playgroud)
基于这个 id 数组,我想从我的“媒体”mysql 表中获取所有行。
$result = $this->db->select('*')
->from('media')
->where_in('id', $ids)
->get()->result_array();
Run Code Online (Sandbox Code Playgroud)
问题是$result数组的值的顺序很奇怪,如下所示:
$result's order : 44, 9 ,0 ,18 ,3 ,392 ,12 ...
Run Code Online (Sandbox Code Playgroud)
但我需要它们保持在我的 $id 字符串/数组顺序中......
到目前为止,我已经尝试了 4 种方法来解决这个问题:
在没有循环的情况下获取行where_in()- 这会产生大量查询 - 但现在有效......
$result根据 the$idstring或 the的顺序对数组重新排序$idarray,尽管我无法找到工作结果,而且我根本不明白为什么需要执行此步骤
尝试修复查询本身。我听说过ORDER_BYand FIND_IN_SET,$ids但我无法将它放入我的工作 codeigniter 查询中,并且不知道性能是否真的有帮助
所以总而言之,我认为这应该是一项简单的日常任务,我只想使用 codeigniter 按给定顺序获取一堆图片。
我在这里错过了一个简单的解决方案吗?