0

我有以下代码,我试图从数组加载图像,如果我尝试加载单个图像它工作正常,但如果我尝试加载多个图像它不会显示任何图像,但我的 divtest在 dom 中。

import React, {Component} from 'react';

class Slider extends Component {

    render() {
        const myItems = [{source_image: '1.jpg'}, {source_image: '2.jpg'}, {source_image: '3.jpg'}];
        return (



                <div id="test">
                    {myItems.map(function (a) {

                            <img src={"images/"+a.source_image}/>
                        }
                    )}
                </div>

        );
    }
}

export default Slider;
4

1 回答 1

1

您忘记在地图中返回:

{myItems.map(function (a) {
        return <img src={"images/"+a.source_image}/> // here
    })
}

{myItems.map(a => <img src={"images/"+a.source_image}/>)} //this is more clear, I think
于 2017-08-30T21:29:13.027 回答