gpt4 book ai didi

javascript - 企业领导不露面

转载 作者:行者123 更新时间:2023-12-02 22:29:43 27 4
gpt4 key购买 nike

因此,我正在尝试完成 coursera 类(class)《使用 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!'
}
];

在 MainComponent 中,我定义了所有导航器

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;

为什么会发生这种情况?这是我的repo .

最佳答案

您不能像在 renderLeaderItem 中那样在渲染函数中定义 const 函数。

如何修复代码:

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

   renderLeaderItem(item, index) {
return (
<ListItem
...
/>
);
}
render(){
return (
...
);
}

将 FlatList 中的代码更改为:

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

工作演示:

https://snack.expo.io/BkFRAwznH

关于javascript - 企业领导不露面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58948116/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com