代码之家  ›  专栏  ›  技术社区  ›  Jay Jeong

react.js公司从函数呈现图像标记

  •  0
  • Jay Jeong  · 技术社区  · 6 年前

    class Test extends Component {
    
    constructor(props) {
    
      super(props);
      this.state = {
          data: null
        }
      this.renderAxis = this.renderAxis.bind(this);
     }
    
    componentDidMount() {
    
      this.setState({
         data: [
                 {
                   name: 'hello',
                   imgUrl: 'https://img.com/someImageUrl',
                   value: 100
                  },
                 {
                   name: 'ola',
                   imgUrl: 'https://img.com/someImageUrl2,
                   value: 50
                  }
               ]
            })
      }
    
      componentDidUpdate(){
    
           this.renderAxis();
        }
    
       renderAxis() {
    
            this.x.domain(this.state.dummyData.map( d => d.name )) // <-- this one works
    
            this.x.domain(this.state.dummyData.map( d => {
            return (
                <img src={d.imgUrl} style={{'width': '30px'}}/> 
            )
        })); // <-- this one does not work
    
        this.y.domain([0, 100]);
    
    ...
    

    以上是我的代码,我相信你已经知道我要做什么了。 我原以为我这样做会把图像而不是纯文本作为记号标签来呈现,但是。。

    0 回复  |  直到 6 年前