【问题标题】:How to route and display a particular object from an array of objects from the database?如何从数据库中的对象数组中路由和显示特定对象?
【发布时间】:2017-02-09 10:18:50
【问题描述】:

下面是我的路由代码。我可以从显示列表路由到信息列表,并且在信息列表中我从数据库中获取所有数据,但我想根据他们的 ID 或其他内容显示一个学生的显示数据。我现在应该怎么做? 并且每次我需要显示不同的学生详细信息。

这是我的路由器。

<Router history={hashHistory}>
    <Route path="/" component={App}/>
    <Route path="/students" component={Students}/>
    <Route path="/holidays" component={Calender}/>
    <Route path="/premontessori" component={Premontessori}/>
    <Route path="/createstudent" component={Createstudent}/>
    <Route path="/montessori1" component={Montessori1}/>
    <Route path="/montessori2" component={Montessori2}/>
    <Route path="/displaylist"  component={Displaylist}/>
    <Route path="/information" component={Information}/>
  </Router>, document.getElementById('app'));

这是我从显示列表到信息列表的链接

<Link  to="/information" style={{textDecoration:'none'}} >

【问题讨论】:

    标签: javascript node.js mongodb reactjs


    【解决方案1】:

    一个超级幼稚的实现看起来有点像这样

    <Route path="/students/:id/" component={Student} />
    
    const Student = React.createClass({
        componentDidMount: function () {
            var id = this.props.params.id;
            return MyAPIClient.get('/path-to-my-api/?studentId=' + id).then(function (data) { this.setState({student: data }.bind(this));
        },
        render: function() {
            // Render your HTML
        }
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-24
    • 1970-01-01
    • 2019-10-11
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    相关资源
    最近更新 更多