【问题标题】:React - dynamic images in a mapReact - 地图中的动态图像
【发布时间】:2017-08-02 01:58:27
【问题描述】:

在这里反应新手。

我有一张标签图 ['a', 'b', 'c']

我有每个图像(a.jpg、b.jpg、c.jpg)

我将如何包含/要求迭代并将每个图像显示为我的地图的一部分?

任何帮助表示赞赏:D

【问题讨论】:

  • 你的标签和地图有关系吗?例如'a' --> a.jpg, 'b' --> b.jpg

标签: image reactjs dictionary react-dom


【解决方案1】:
var Foo = React.createClass({
  render: function() {
   const images = ['a','b','c']
   const imagesElements = images.map( e => {
    return (
     <img src={`${e}.jpg`} />
    )
   });

   return(
    <div>
     {imagesElements}
    </div>
   )
 }
});

ReactDOM.render(
 <Foo name="bar" />,
 document.getElementById('container')
);

https://jsfiddle.net/69z2wepo/83751/

【讨论】:

  • 谢谢先生!最有帮助的一点 - {${e}.jpg} - 现在更有意义了。谢谢!
  • 当然,随时:)
猜你喜欢
  • 2016-06-22
  • 2017-05-16
  • 1970-01-01
  • 2022-07-20
  • 1970-01-01
  • 2012-10-30
  • 2017-04-03
  • 2015-12-13
相关资源
最近更新 更多