Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs {mineral.classType} 骨折 {矿物断裂} 硬度 {矿物硬度} ); } } MinCard.propTypes={ 矿物:PropTypes.object.isRequired, };_Reactjs_Ecmascript 6_React Jsx_Meteor React - Fatal编程技术网

Reactjs {mineral.classType} 骨折 {矿物断裂} 硬度 {矿物硬度} ); } } MinCard.propTypes={ 矿物:PropTypes.object.isRequired, };

Reactjs {mineral.classType} 骨折 {矿物断裂} 硬度 {矿物硬度} ); } } MinCard.propTypes={ 矿物:PropTypes.object.isRequired, };,reactjs,ecmascript-6,react-jsx,meteor-react,Reactjs,Ecmascript 6,React Jsx,Meteor React,我认为您遇到的问题源于这段代码: renderMinerals () { return this.props.minerals.map((mineral) => ( <MinList key={mineral._id} mineral={mineral}/> )); } renderMinerals(){ 返回此.props.minerals.map((矿物)=>( )); } map函数没有返回任何内容,因此renderMinerals

我认为您遇到的问题源于这段代码:

renderMinerals () {
    return  this.props.minerals.map((mineral) => (

        <MinList key={mineral._id} mineral={mineral}/>
    ));
}
renderMinerals(){
返回此.props.minerals.map((矿物)=>(
));
}
map
函数没有返回任何内容,因此renderMinerals函数将返回
[未定义、未定义、未定义]
的数组

尝试使用
return()


编辑:另一个技巧是在渲染函数中为
MinList
设置断点,并检查
this.props.mineral
是否
未定义
首先感谢Paqash为我指出了正确的方向,问题是该组件在数据可用之前已安装。所以经过一些研究,我找到了这个话题

我需要一个getMeteorData()函数,从那里我可以控制订阅准备就绪和未准备就绪时会发生什么。由于这个函数,我还不得不将map函数更改为this.data.minerals,更改后的页面如下。我希望这能帮助其他人找到解决这个问题的方法

import React, { Component, PropTypes } from 'react';

import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import {List} from 'material-ui/List';
import AppBar from 'material-ui/AppBar';
import IconButton from 'material-ui/IconButton';
import NavigationClose from 'material-ui/svg-icons/navigation/close';
import {Link} from 'react-router';
import {ReactMeteorData} from 'meteor/react-meteor-data';
import {Meteor} from 'meteor/meteor';
import {Minerals} from '../../api/minerals';
import MinList from './MinList';
import ReactMixin from 'react-mixin';

export default class ListPage extends Component {

    constructor(props) {
        super(props);
    }
    getChildContext() {
        return { muiTheme: getMuiTheme(baseTheme) };
    }
    //New Function Needed
    getMeteorData(){
        const handle = Meteor.subscribe('minerals');

        return {
            ready: handle.ready(),
            minerals: Minerals.find({}, {sort: {name: 1}}).fetch(),
        };
    }

    renderMinerals () {
        return  this.data.minerals.map((mineral) => (

            <MinList key={mineral._id} mineral={mineral}/>
        ));
    }

    render() {
        //Wrapped render in if data ready bool
        if(!this.data.ready){
            return (
                <div className="container">
                    <AppBar
                        iconElementLeft={<IconButton><Link to="/"><NavigationClose/></Link></IconButton>}
                        title="Mineral ID"
                    />
                <div>Loading</div>
            </div>
            );
        } else {

            return (
                <div className="container">
                    <AppBar
                        iconElementLeft={<IconButton><Link to="/"><NavigationClose/></Link></IconButton>}
                        title="Mineral ID"
                    />
                    <List>
                        {   this.renderMinerals()   }
                    </List>
                </div>
            );
        }
    }
}

//Added
ReactMixin(ListPage.prototype, ReactMeteorData);

ListPage.propTypes = {
    minerals: PropTypes.array.isRequired,

};

ListPage.childContextTypes = {
    muiTheme: React.PropTypes.object.isRequired,
};
import React,{Component,PropTypes}来自'React';
从“材质ui/styles/baseThemes/LightBaseThemes”导入baseTheme;
从“材质ui/styles/GetMuiteme”导入GetMuiteme;
从“物料界面/列表”导入{List};
从“物料ui/AppBar”导入AppBar;
从“物料界面/图标按钮”导入图标按钮;
从“材质ui/svg图标/navigation/close”导入NavigationClose;
从“反应路由器”导入{Link};
从“流星/反应流星数据”导入{ReactMeteorData};
从“流星/流星”导入{Meteor};
从“../../api/Minerals”进口{Minerals}”;
从“/MinList”导入MinList;
从“react mixin”导入ReactMixin;
导出默认类ListPage扩展组件{
建造师(道具){
超级(道具);
}
getChildContext(){
返回{muiTheme:getMuiTheme(baseTheme)};
}
//需要新功能
getMeteorData(){
常量句柄=流星订阅(“矿物”);
返回{
ready:handle.ready(),
minerals:minerals.find({},{sort:{name:1}}).fetch(),
};
}
renderMinerals(){
返回此.data.minerals.map((mineral)=>(
));
}
render(){
//如果数据就绪,则包装渲染布尔
如果(!this.data.ready){
返回(
加载
);
}否则{
返回(
{this.renderMinerals()}
);
}
}
}
//增加
ReactMixin(ListPage.prototype,ReactMeteorData);
ListPage.propTypes={
矿物:需要PropTypes.array.isRequired,
};
ListPage.childContextTypes={
muiTheme:React.PropTypes.object.isRequired,
};

Paqash非常感谢您的帮助。不幸的是,您给出的代码建议不起作用,因为我使用矿物的映射来获取每个矿物对象,然后使用这些矿物对象生成minlist对象。根据您的建议,虽然我使用了断点,您对此的看法是正确的。props.minerals.map未定义,但我认为这是因为meteor.subscribe尚未准备好。我试着在下面设置一个等待就绪代码,然后在中返回加载,所以我认为我的思路是正确的。导出默认createContainer(()=>{while(!Meteor.subscribe('minerals').ready(){return加载;}return{minerals:minerals.find({},{sort:{name:1},limit 10})。fetch(),};},MinList);
import React, {Component, PropTypes} from 'react';
import {Card, CardMedia, CardText} from 'material-ui/Card';
import {Table, TableBody, TableRow, TableRowColumn} from 'material-ui/Table';

const tableStyle={
    fontSize: '15px',
};


export default class MinCard extends Component {

    render() {
        const mineral = this.props.mineral;
        return (
      <Card>
                <CardMedia mediaStyle={{height: '50%', width: '50%', margin: 'auto'}}>
                <img src={'./img/'+this.props.mineral.minName+'.jpg'}/>
                </CardMedia>
                <CardText>
                    <h5>Summary</h5>
          {mineral.summary}
        </CardText>
                <Table>
                    <TableBody
                        displayRowCheckbox={false}
                        >
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Formula
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.formula}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Crystal System
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.crystalSystem}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Crystal Habit
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.crystalHabit}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Cleavage
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.cleavage}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Luster
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.luster}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Color
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.color}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Streak
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.streak}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Class Type
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.classType}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Fracture
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.fracture}
                            </TableRowColumn>
                        </TableRow>
                        <TableRow
                            selectable={false}
                            >
                            <TableRowColumn style={tableStyle}>
                                Hardness
                            </TableRowColumn>
                            <TableRowColumn style={tableStyle}>
                                {mineral.hardness}
                            </TableRowColumn>
                        </TableRow>
                    </TableBody>
                </Table>
      </Card>
        );
    }
}

MinCard.propTypes = {
    mineral: PropTypes.object.isRequired,
};
renderMinerals () {
    return  this.props.minerals.map((mineral) => (

        <MinList key={mineral._id} mineral={mineral}/>
    ));
}
import React, { Component, PropTypes } from 'react';

import baseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
import getMuiTheme from 'material-ui/styles/getMuiTheme';
import {List} from 'material-ui/List';
import AppBar from 'material-ui/AppBar';
import IconButton from 'material-ui/IconButton';
import NavigationClose from 'material-ui/svg-icons/navigation/close';
import {Link} from 'react-router';
import {ReactMeteorData} from 'meteor/react-meteor-data';
import {Meteor} from 'meteor/meteor';
import {Minerals} from '../../api/minerals';
import MinList from './MinList';
import ReactMixin from 'react-mixin';

export default class ListPage extends Component {

    constructor(props) {
        super(props);
    }
    getChildContext() {
        return { muiTheme: getMuiTheme(baseTheme) };
    }
    //New Function Needed
    getMeteorData(){
        const handle = Meteor.subscribe('minerals');

        return {
            ready: handle.ready(),
            minerals: Minerals.find({}, {sort: {name: 1}}).fetch(),
        };
    }

    renderMinerals () {
        return  this.data.minerals.map((mineral) => (

            <MinList key={mineral._id} mineral={mineral}/>
        ));
    }

    render() {
        //Wrapped render in if data ready bool
        if(!this.data.ready){
            return (
                <div className="container">
                    <AppBar
                        iconElementLeft={<IconButton><Link to="/"><NavigationClose/></Link></IconButton>}
                        title="Mineral ID"
                    />
                <div>Loading</div>
            </div>
            );
        } else {

            return (
                <div className="container">
                    <AppBar
                        iconElementLeft={<IconButton><Link to="/"><NavigationClose/></Link></IconButton>}
                        title="Mineral ID"
                    />
                    <List>
                        {   this.renderMinerals()   }
                    </List>
                </div>
            );
        }
    }
}

//Added
ReactMixin(ListPage.prototype, ReactMeteorData);

ListPage.propTypes = {
    minerals: PropTypes.array.isRequired,

};

ListPage.childContextTypes = {
    muiTheme: React.PropTypes.object.isRequired,
};