Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何为Array.map中的特定实体应用样式属性?_Javascript_Reactjs_Jsx - Fatal编程技术网

Javascript 如何为Array.map中的特定实体应用样式属性?

Javascript 如何为Array.map中的特定实体应用样式属性?,javascript,reactjs,jsx,Javascript,Reactjs,Jsx,我正在做一个滑动条的事情,但我面临一个问题,如何为特定的文章应用left属性?例如,仅为索引1应用left=20px?您可以为其余部分提供left=0: const imageHtml = imageDescription.map((article, index) => { return ( <div style={{ backgroundImage: "url(/images/Large/" + article.imagePa

我正在做一个滑动条的事情,但我面临一个问题,如何为特定的文章应用left属性?例如,仅为索引1应用left=20px?

您可以为其余部分提供left=0:

const imageHtml = imageDescription.map((article, index) => {
            return (
                <div style={{ backgroundImage: "url(/images/Large/" + article.imagePath + ".jpg)" }}>

                </div>
            )
        })
或者,如果您不想包含它:

<div style={{backgroundImage: ..., left: (index === 1 ? 20 : 0)}} />
<div style={Object.assign({backgroundImage: ...}, (index === 1 ? {left: 20} : {}))} />