代码之家  ›  专栏  ›  技术社区  ›  TheAmplifier

空对象meteor/react的回退消息

  •  0
  • TheAmplifier  · 技术社区  · 8 年前

    Object.getOwnPropertyNames() 但无法使其工作,因为未调用映射函数。我不知道该将此检查放在何处,在呈现函数内,在模板内的with tracker或render调用中。

    我使用Meteor/react,代码如下:

    import React, {Component} from 'react';
    import {withTracker} from 'meteor/react-meteor-data';
    import {Link} from 'react-router-dom';
    
    class ArchiveCustomerOverview extends Component {
      renderCustomerList() {
        return this.props.users.map( user => {
            return(
                <div className="row" key={user._id}>
                    <Link to={}>
                        <span className="medium-1">{user.profile.name}</span>
                        <span className="medium-4">{user.profile.company}</span>
                        <span className="medium-3">{user.profile.phone}</span>
                        <span className="medium-3">{user.emails[0].address}</span>
                    </Link>
                </div>
            )
        });
    }
    render() {
        return (
            <div>
                <div className="list-overview">
                    <div className="list-wrapper">
                        <div className="list-box clear">
                            {this.renderCustomerList()}
                        </div>
                    </div>
                </div>
            </div>
        );
      }
    }
    export default withTracker( (props) => {
      Meteor.subscribe('users');
       return { 
        users: Meteor.users.find({
            'profile.isArchived': 0,
            'roles.customers'       : 'customer'
        }).fetch() 
      };
    })(ArchiveCustomerOverview);
    
    1 回复  |  直到 8 年前
        1
  •  1
  •   Mikkel    8 年前

    只需检查用户数,然后再按以下方式渲染:

      renderCustomerList() {
        if (this.props.users.length === 0) {
          return (<div>Currently there are no customers available</div>)
        }
        return this.props.users.map( user => {
    

    但有一点需要提醒:您可能无法从users集合中获得所需的内容—出于安全原因,它的处理方式与其他集合不同。