如何在我的结果中显示我现在拥有的数据?

时间:2017-12-20 10:28:36

标签: javascript arrays reactjs react-native

import React, { Component } from 'react';
import './Video.css';

class Video extends Component{
    constructor(props){
        super(props);
        this.sortIT = this.sortIT.bind(this);
        this.state = { isHide : false};
        this.state = { isResult:[]};
        this.state = { isShow : true}
    }
    sortIT(){
        const finalItVideos = [] 
        this.setState({isHide:true});
        videoList.map((video,i)=>{
            const videosOfIT = video;
            const keyOfVideo = video.key;
            if(keyOfVideo === "IT"){    
                finalItVideos.push(videosOfIT);
            }
        })
        this.setState({isShow : false});
        this.setState({isResult:finalItVideos})
    }


    render(){
        const  hideClass = this.state.isHide ? "hide" : "show";
        const result = this.state.isResult;
        const showClass = this.state.isShow ? "hide" : "show";

        return(

            <div>
            {result}
            <div id="videoContainer" className="container-fluid">
            <div className="row">
            <div className="col-xs-12 col-sm-3">
            |<br /><b>  Our Videos</b><br />
            <b>You Looking for ?</b>
            <p onClick={this.sortIT}>IT Industry</p>
            <p>Lean Canvas</p>
            <p>Wedding Invitations</p>
            <p>Video Resumes</p>
            <p>App Explainers</p>
            <p>Video Presentations</p>
            <p>Video Campaigns</p>          </div><br />
            <div className={showClass}>
            {this.finalItVideos}
            </div>

            {videoList.map((video, i)=>(
                <div key={i} className={hideClass}>
                {video.images.map((image,index)=>(
                    <VideoItem imageUrl={image} key={index} />
                    ))}
                </div>  
                ))}
            </div>
            <br />
            <button className="btn">
            <i className="fa fa-play fa-rotate-180" aria-hidden="true"></i> 
            &nbsp;Load More
            </button>

            </div>
            </div>
            );
    }


}

export default Video;
class VideoItem extends React.Component {
    render() {
        return (
            <div>
            {this.props.imageUrl}
            </div>
            )
    }
}


const videoList = [video Array]
}
]

如何在我的数组中显示数据,如下所示

{
    key: "Birthday",
    images: [<div name="IT"  className="col-xs-12 col-sm-3">
    <div className="content">
    <div className="content-overlay"></div>
    <img className="content-image" src={require('./139923200.PNG')} />
    <div className="content-details fadeIn-top">
    <h3>This is a title</h3>
    <a data-fancybox href="https://vimeo.com/139923200?autoplay=1&HD=1"><h4><i className="fa fa-play" aria-hidden="true"></i>
    &nbsp;Click To Play</h4></a></div></div>
    </div>]
}

我在我的结果数组中有三个,如果我使用map它的说法地图没有定义,如果我把它直接放这是错误

未捕获错误:对象作为React子对象无效(找到:具有键{key,images}的对象)。如果您要渲染子集合,请改用数组。

如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您在构造函数中重写状态3次。你应该这样做:

2017-12-20 08:40:00,013+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change WAITING -> RUNNING
2017-12-20 08:40:00,051+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change RUNNING -> WAITING (OK)
2017-12-20 08:50:00,014+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change WAITING -> RUNNING
2017-12-20 08:50:00,029+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change RUNNING -> WAITING (OK)
2017-12-20 09:00:00,015+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change WAITING -> RUNNING
2017-12-20 09:00:00,031+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change RUNNING -> WAITING (OK)
2017-12-20 09:10:00,016+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change WAITING -> RUNNING
2017-12-20 09:10:00,032+0100 INFO  [quartz-3-thread-19]  *SYSTEM org.sonatype.nexus.quartz.internal.task.QuartzTaskInfo - Task 'Storage facet cleanup' [repository.storage-facet-cleanup] state change RUNNING -> WAITING (OK)

现在你可以执行isResult.map(),因为isResult至少是一个空数组,你不会有地图错误。