Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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
Javascript 公司领导不会表现出来_Javascript_React Native - Fatal编程技术网

Javascript 公司领导不会表现出来

Javascript 公司领导不会表现出来,javascript,react-native,Javascript,React Native,因此,我正试图通过coursera的React Native课程完成第一周的多平台移动应用程序开发任务 在其中一项任务中,我将在“关于美国”导航项中向公司领导展示 export const LEADERS = [ { id: 0, name: 'Peter Pan', image: '/assets/images/alberto.png', designation: 'Chief Epicurious Officer', abbr: 'CEO',

因此,我正试图通过coursera的React Native课程完成第一周的多平台移动应用程序开发任务

在其中一项任务中,我将在“关于美国”导航项中向公司领导展示

export const LEADERS = [
  {
    id: 0,
    name: 'Peter Pan',
    image: '/assets/images/alberto.png',
    designation: 'Chief Epicurious Officer',
    abbr: 'CEO',
    featured: false,
    description: "Our CEO, Peter, credits his hardworking East Asian immigrant parents who undertook the arduous journey to the shores of America with the intention of giving their children the best future. His mother's wizardy in the kitchen whipping up the tastiest dishes with whatever is available inexpensively at the supermarket, was his first inspiration to create the fusion cuisines for which The Frying Pan became well known. He brings his zeal for fusion cuisines to this restaurant, pioneering cross-cultural culinary connections."
  },
  {
    id: 1,
    name: 'Dhanasekaran Witherspoon',
    image: '/assets/images/alberto.png',
    designation: 'Chief Food Officer',
    abbr: 'CFO',
      featured: false,
    description: 'Our CFO, Danny, as he is affectionately referred to by his colleagues, comes from a long established family tradition in farming and produce. His experiences growing up on a farm in the Australian outback gave him great appreciation for varieties of food sources. As he puts it in his own words, Everything that runs, wins, and everything that stays, pays!'
  },
  {
    id: 2,
    name: 'Agumbe Tang',
    image: '/assets/images/alberto.png',
    designation: 'Chief Taste Officer',
    abbr: 'CTO',
      featured: false,
    description: 'Blessed with the most discerning gustatory sense, Agumbe, our CFO, personally ensures that every dish that we serve meets his exacting tastes. Our chefs dread the tongue lashing that ensues if their dish does not meet his exacting standards. He lives by his motto, You click only if you survive my lick.'
  },
  {
    id: 3,
    name: 'Alberto Somayya',
    image: '/assets/images/alberto.png',
    designation: 'Executive Chef',
    abbr: 'EC',
    featured: true,
    description: 'Award winning three-star Michelin chef with wide International experience having worked closely with whos-who in the culinary world, he specializes in creating mouthwatering Indo-Italian fusion experiences. He says, Put together the cuisines from the two craziest cultures, and you get a winning hit! Amma Mia!'
  }
];
在main组件中,我定义了所有的导航器

import React, { Component } from 'react';
import Menu from './MenuComponent';
import Dishdetail from './DishDetailComponent';
import { View, Platform } from 'react-native';
import { createStackNavigator, createDrawerNavigator } from 'react-navigation';
import Home from './HomeComponent';
import About from './AboutComponent';
import Contact from './ContactComponent';

const MenuNavigator = createStackNavigator({
    Menu: { screen: Menu },
    Dishdetail: { screen: Dishdetail }
}, {
    initialRouteName: 'Menu',
    navigationOptions: {
      headerStyle: {
        backgroundColor: '#512DA8'
      }, 
      headerTintColor: '#fff',
      headerTitleStyle: {
        color: '#fff'
      }
    }
});

const HomeNavigator = createStackNavigator({
  Home: { screen: Home }
}, {
    navigationOptions: {
        headerStyle: {
            backgroundColor: '#512DA8'
        },
        headerTintColor: '#fff',
        headerTitleStyle: {
            color: '#fff'
        }
    }
});

const AboutNavigator = createStackNavigator({
  About: { screen: About },
}, {
  navigationOptions: {
      headerStyle: {
          backgroundColor: '#512DA8'
      },
      headerTintColor: '#fff',
      headerTitleStyle: {
          color: '#fff'
      }
  }
});

const ContactNavigator = createStackNavigator({
  Contact: { screen: Contact },
}, {
  navigationOptions: {
      headerStyle: {
          backgroundColor: '#512DA8'
      },
      headerTintColor: '#fff',
      headerTitleStyle: {
          color: '#fff'
      }
  }
});

const MainNavigator = createDrawerNavigator({
  Home: {
      screen: HomeNavigator,
      navigationOptions: {
          title: 'Home',
          drawerLabel: 'Home'
      }
  },
  About: {
    screen: AboutNavigator,
    navigationOptions: {
        title: 'About Us',
        drawerLabel: 'About Us'
    }    
  },
  Menu: {
      screen: MenuNavigator,
      navigationOptions: {
          title: 'Menu',
          drawerLabel: 'Menu'
      }    
  },
  Contact: {
    screen: ContactNavigator,
    navigationOptions: {
        title: 'Contact Us',
        drawerLabel: 'Contact Us'
    }    
  },
}, {
  drawerBackgroundColor: '#D1C4E9',
})

class Main extends Component {

  render() {
    return (
      <View style={{flex:1}}>
        <MainNavigator />
      </View>
    );
  }
}

export default Main;
最后,我定义了AboutComponent.js,在这里我试图显示一个公司领导的列表

import React, { Component } from 'react';
import { FlatList,ScrollView, Text,View } from 'react-native';
import LEADERS from '../shared/leaders';
import { ListItem, Card } from 'react-native-elements';

class About extends Component {

    constructor(props){
        super(props);
        this.state = {
            leaders: LEADERS
        }
    }

    static navigationOptions = { 
        title: 'About us'
    }


    render(){

        const renderLeaderItem = ({item, index}) => {

            return (
                    <ListItem
                        key={index}
                        title={item.name}
                        subtitle={item.description}
                        hideChevron={true}
                        leftAvatar={{ source: require('./images/uthappizza.png') }}
                      />
            );
        };

        return (
            <ScrollView>
                <Card title="Our History">
                    <Text>Started in 2010, Ristorante con Fusion quickly established itself as a culinary icon par excellence in Hong Kong. With its unique brand of world fusion cuisine that can be found nowhere else, it enjoys patronage from the A-list clientele in Hong Kong.  Featuring four of the best three-star Michelin chefs in the world, you never know what will arrive on your plate the next time you visit us.</Text>
                    <Text>The restaurant traces its humble beginnings to The Frying Pan, a successful chain started by our CEO, Mr. Peter Pan, that featured for the first time the world's best cuisines in a pan.</Text>
                </Card>
                <Card title="Corporate Leadership">                    
                    <FlatList 
                        data={this.state.leaders}
                        renderItem={renderLeaderItem}
                        keyExtractor={item => item.id.toString()}
                    />
                </Card>
            </ScrollView>
        )
    }

}


export default About;

为什么会这样?这是我的。

不允许像使用renderLeaderItem一样在渲染函数中定义常量函数

如何修复代码:

在渲染函数外部创建renderLeaderItem,例如:

   renderLeaderItem(item, index) {
            return (
                    <ListItem
                       ...
                      />
            );
    }
    render(){ 
       return ( 
       ... 
       );
    } 
将平面列表中的代码更改为:

<FlatList 
 data={this.state.leaders}
 renderItem={({item, index}) => this.renderLeaderItem(item,index)}
 keyExtractor={item => item.id.toString()}
/>
工作演示: