【发布时间】:2020-04-14 00:04:22
【问题描述】:
我正在使用 React 和 pnp 控件为 SharePoint Online 开发 spfx Web 部件
我正在使用 pnp 控件 Carousel
<Carousel
buttonsLocation={CarouselButtonsLocation.top}
buttonsDisplay={CarouselButtonsDisplay.block}
contentContainerStyles={styles.carouselContent}
containerButtonsStyles={styles.carouselButtonsContainer}
isInfinite={true}
element={this.carouselElements}
onMoveNextClicked={(index: number) => { console.log(`Next button clicked: ${index}`); }}
onMovePrevClicked={(index: number) => { console.log(`Prev button clicked: ${index}`); }}
/>
在上面的控制元素={this.carouselElements}
属性需要根据'key'属性区分的元素数组
现在我创建了另一个组件,呈现如下:
public render(): React.ReactElement<IHomePageCarouselProps> {
return (
<div className={styles.homePageCarousel}>
{/* <div className="owl-carousel owl-theme owl-banner "> */}
<div key="1">
<a href="#">
<img src="images/banner_1.jpg " alt="banner" className="rounded-top" />
</a>
<div className="bg-white rounded-bottom p-10">
<span className="font-color-green font-weight-bold ">
News title will show here. News title will show here. News title will show
here. News title will show here. News title will show here. News title will
show here. News title will show here. News title will show here. ...
</span>
</div>
</div>
<div key="2">
<a href="#">
<img src="images/banner_1.jpg " alt="banner" className="rounded-top" />
</a>
<div className="bg-white rounded-bottom p-10">
<span className="font-color-green font-weight-bold ">
News title will show here. News title will show here. News title will show
here. News title will show here. News title will show here. News title will
show here. News title will show here. News title will show here. ...
</span>
</div>
</div>
{/* </div> */}
</div>
)
}
在轮播元素属性中使用上述组件如下:
element={<HomePageCarousel />}
但是HomePageCarousel 不能在没有主div 的情况下渲染,这是React 的要求。有人可以帮助我如何输出或提取元素数组吗?
【问题讨论】:
标签: javascript reactjs sharepoint-online spfx