cannot add a child that doesnot have a YogoNode to a parent without a measure function!
来源:互联网 发布:上海linux运维培训 编辑:程序博客网 时间:2024/04/29 17:19
最近在学习rn,各种报错和坑,而且对语法也不熟悉,为啥要用{}这种形式呢?唉,还是我大java好,不扯淡了。
在使用FlatList的时候,老是报
cannot add a child that doesnot have a YogoNode to a parent without a measure function!(Trying to add a 'ReactRawTextShadowNode' to a 'LayoutShadowNode')
这个错,然后我反复找我的代码,是真的没有错,代码如下
import React, {Component} from 'react';import {StyleSheet,View,FlatList,Text,Button,Dimensions} from 'react-native';const {width,height}=Dimensions.get('window')export default class FlatDemo extends Component{ render(){ return( <View style={styles.container}> <FlatList data={[ {key:'haha1'}, {key:'haha2'}, {key:'hah3'}, {key:'heihei4'}, {key:'john'}, {key:'aaa'}, {key:'bbb'}, {key:'ccc'}, {key:'ddd'} ]} renderItem={({item})=><Text style={styles.item}>{item.key}</Text>} /> </View> ); }}const styles=StyleSheet.create({ container:{ flex:1, paddingTop:120 }, item: { padding: 10, fontSize: 18, height: 44, }})特么的,这哪里有错啊,就当我百思不得其解的时候,我决定把这个文件去掉,直接写在App.js中
import React, { Component} from 'react';import { Platform, StyleSheet, Text, View, FlatList} from 'react-native';export default class App extends Component{ render(){ var params = {name:'小明',age:29,sex:'女'}; var {name,age}=params; return( <View style={styles.container}> <FlatList data={[ {key:'嘿嘿'}, {key:'嘿嘿2'}, {key:'嘿嘿3'}, {key:'嘿嘿4'}, {key:'嘿嘿5'}, {key:'嘿嘿6'}, ]} renderItem={({item})=><Text style={styles.item}>{item.key}</Text>} /> </View> ); }}const styles=StyleSheet.create({ container:{ flex:1, paddingTop:20 }, item: { padding: 10, fontSize: 18, height: 44, }})不幸的是,还是报同样的错,然后各种google,baidu还是没有结果,忘了说了,我当前rn版本是0.50,我就想把根view去掉试试
import React, { Component} from 'react';import { Platform, StyleSheet, Text, View, FlatList} from 'react-native';export default class App extends Component{ render(){ var params = {name:'小明',age:29,sex:'女'}; var {name,age}=params; return( <FlatList style={styles.container} data={[ {key:'嘿嘿'}, {key:'嘿嘿2'}, {key:'嘿嘿3'}, {key:'嘿嘿4'}, {key:'嘿嘿5'}, {key:'嘿嘿6'}, ]} renderItem={({item})=><Text style={styles.item}>{item.key}</Text>} /> ); }}const styles=StyleSheet.create({ container:{ flex:1, paddingTop:20 }, item: { padding: 10, fontSize: 18, height: 44, }})这样就成功了,卧槽,这样搞得话,岂不是一个页面只能使用FlatList,难道就不能和其他view一起用了?
后续更新中.......小伙伴要是有碰到的,已经解决的给我留言啊!不胜感激。
2017/12/5更新
不要在你的flatList里面使用注释
Some times you need to remove the extra spaces between the angle brackets to get rid of it.这是facebook官方人员回复的,希望对大家有帮助!!!
2017/12/7更新
不要在你的render里的return里的根view里面使用注释
阅读全文
0 0
- cannot add a child that doesnot have a YogoNode to a parent without a measure function!
- Have a first child
- How to find child controls that are located in the template of a parent control
- JESUS TO A CHILD
- csharp: DataRelation objects to represent a parent/child/Level relationship
- csharp: DataRelation objects to represent a parent/child/Level relationship
- MySQL外键 Cannot add or update a child row
- mysql cannot add or update a child row
- I have a dream that...
- a declaration cannot have a label
- After Adding a Product Redirect to Shopping Cart doesnot work
- The specified child already has a parent.
- The specified child already has a parent
- Teh specified child already has a parent
- The specified child already has a parent
- The specified child already has a parent
- Cannot create children for a parent that is in a different thread
- QObject: Cannot create children for a parent that is in a different thread
- jQuery对象 与 js对象 区别与联系
- SpringBoot的简单入门
- ssm框架开发定时任务到达某一个时间点自动更新数据
- 欢迎使用CSDN-markdown编辑器
- 2.3 寻找发帖"水王"
- cannot add a child that doesnot have a YogoNode to a parent without a measure function!
- 对链表的基本实现和各种操作
- ncnn实例教程
- linux下模拟登陆环境安装
- iOS开发
- DevExpress v17.2新版亮点—WinForms篇(三)
- github上十二款Android播放器开源项目
- 从博客园博问站点迁移ASP.NET Core展望.NET Core
- Ruby String常用函数