2017-08-30 84 views
0

我有以下代碼,我想從數組中加載圖像,如果我嘗試加載單個圖像,它工作正常,但如果我嘗試加載多個圖像它劑量顯示任何圖像,我的div test是在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; 

回答

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 
+0

感謝,我不能形容愚蠢覺得我來到這裏。 –

+0

要更細心:) – Andrew