显示基于该部分的项目

时间:2018-01-02 07:01:02

标签: javascript reactjs react-native

我想显示与该部分相关的部分和项目。我的意思是以下方式

  

逾期

     

ITEM1

     

ITEM2

     

项目3

     

没有到期

     

ITEM1

     

ITEM2

     

项目3

我尝试了以下方式,但是这样,我无法生成上面的ui。我该怎么做?

我有来自服务器的以下数据 的 START_TIME, 时间结束, 提醒内容, 标题, _id

这是我试过的

 $imagePath = '/image/folder/';
 $uniquesavename=time().uniqid(rand());
 $destFile = $imagePath . $uniquesavename . '.jpg';
 $filename = $_FILES["img"]["tmp_name"];
 list($width, $height) = getimagesize( $filename );       
 move_uploaded_file($filename,  $destFile);

尝试以下列方式使用const ListItem = ({task}) => { const current_time = new Date(); if (current_time > task.end_time) { return <View key={task._id} style={{flexDirection: 'column', flex: 1}}> <Text>overdue</Text> <Text>{task.title}</Text> <Text>{task.start_time}</Text> </View> } return ( <View key={task._id} style={{flexDirection: 'column', flex: 1}}> <Text>{task.title}</Text> <Text>{task.start_time}</Text> </View> ) } const List = ({query}) => { console.log('query', query); if(query.loading) return <Text>Loading...</Text> if(query.error) return <Text>Error...</Text> return ( <Wrapper> <View style={{flexDirection: 'row', marginLeft: 10, marginTop: 10}}> <Image resizeMode="contain" source={newIcon} style={{width: 25, height: 25}} /> <Text style={{ alignSelf: 'center', color: '#1F84DD' }}> New Task </Text> </View> <FlatList data={query.tasks} renderItem={({item}) => <ListItem task={item} />} /> </Wrapper> ) }

SectionList

这样我就会收到错误

  

不变违规:对象无效作为React子对象(找到:对象   使用键_id,start_time,end_time,remincer_time)

1 个答案:

答案 0 :(得分:0)

我看到一种可能的解决方案。在部分列表代码中,您将在文本组件中打印项目对象,它应该是标题。 替换renderItem = {({item})=&gt; {item}}与renderItem = {({item})=&gt; {item.titke}}

感谢。