我的数据库中有一个属性product_des,其中存储了所有内容react draft wysiwyg。我想从数据库中设置编辑器的默认值。
//State
const [onEditorStateChange, setOnEditorStateChange] = useState<any>()
const [content, setContent] = useState<any>()
<Editor
editorState={onEditorStateChange}
toolbarClassName="toolbarClassName"
wrapperClassName="wrapperClassName"
editorClassName="editorClassName"
onEditorStateChange={newState => {
setOnEditorStateChange(newState)
setContent(draftToHtml(convertToRaw(newState.getCurrentContent())))
}}
/>
Run Code Online (Sandbox Code Playgroud)
这是我的数据库示例:
{
_id: "6231a09c0a292231f0bbd16b",
title: "Controller",
reg_price: "499",
product_des: "<p>PS5</p>
"
}
Run Code Online (Sandbox Code Playgroud) 我试图从数组对象中仅获取 2 个属性。
这是我的数组:
[
0: {_id: '621723ddc1f73de5f7e4dcb9', label: 'new 22', slug: 'new-22', vendor: 'admin', options: Array(1)}
1: {_id: '6217272ec1f73de5f7e4dcba', label: 'new 33', slug: 'new-33', vendor: 'admin', options: Array(1)}
]
Run Code Online (Sandbox Code Playgroud)
我试图只获得标签和标签,我的期望是:
[
0: {label: 'new 22', slug: 'new-22'}
1: {label: 'new 33', slug: 'new-33'}
]
Run Code Online (Sandbox Code Playgroud)
我尝试过这样的方式:但它返回完整的数组对象
let tempArray;
for (let i = 0; i < data.length; i += 2) {
tempArray = data.slice(data[i], data[i + 2]);
}
setAttributeLabel(tempArray);
Run Code Online (Sandbox Code Playgroud) 我正在使用反应打字稿。当我设置thumbs={{ swiper: thumbsSwiper }}滑动滑块组件时,它给我一个错误Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'addClass')。我怎样才能解决它?如果我在 js 文件中使用以下代码,它不会给我任何错误,但一旦我在 TSX 文件上使用它,就会出现错误。
const [thumbsSwiper, setThumbsSwiper] = useState<any>(null); // Thumbs state
<div key={product._id} className='lg:w-1/2'>
<Swiper
loop={true}
spaceBetween={10}
thumbs={{ swiper: thumbsSwiper }} // PRoblem is Here
modules={[FreeMode, Navigation, Thumbs]}
className="mySwiper2"
>
{product?.images.map(({ src }: { src: string }) => {
return <SwiperSlide style={{ height: '500px', width: '300px' }}>
<img src={src} alt={product?.title} />
</SwiperSlide>
})}
</Swiper>
<Swiper
onSwiper={setThumbsSwiper}
loop={true}
spaceBetween={10}
slidesPerView={4}
freeMode={true}
watchSlidesProgress={true} …Run Code Online (Sandbox Code Playgroud)