ReactNativeiOS(三)开发零碎3 warning: Each child in ar array or integrator should have a unique "key" prop
2015-12-31 22:20
567 查看
原为:
render() {
return (
<ScrollView style={styles.container}>
<View style={styles.imageGrid}>
{ this.state.images.map((image) => {
return (
<TouchableHighlight onPress={this.selectImage.bind(null, image.uri)}>
*/
{ this.state.images.map((image, i) => {
return (
<TouchableHighlight key={i} onPress={this.selectImage.bind(null, image.uri)}>
<Image style={styles.image} source={{ uri: image.uri }} />
</TouchableHighlight>
);
})
}
</View>
</ScrollView>
);
}
出了个Warning: Each child in ar array or integrator should have a unique "key" prop
查了半天,在这里似乎得到答案 http://stackoverflow.com/questions/28329382/understanding-unique-keys-for-array-children-in-react-js
改为:
render() {
return (
<ScrollView style={styles.container}>
<View style={styles.imageGrid}>
{ this.state.images.map((image, i) => {//此处加了 ,i)
return (
<TouchableHighlight key={i} onPress={this.selectImage.bind(null, image.uri)}>//此处加了 key={i}
<Image style={styles.image} source={{ uri: image.uri }} />
</TouchableHighlight>
);
})
}
</View>
</ScrollView>
);
}
warning 消失,,,yeah!
render() {
return (
<ScrollView style={styles.container}>
<View style={styles.imageGrid}>
{ this.state.images.map((image) => {
return (
<TouchableHighlight onPress={this.selectImage.bind(null, image.uri)}>
*/
{ this.state.images.map((image, i) => {
return (
<TouchableHighlight key={i} onPress={this.selectImage.bind(null, image.uri)}>
<Image style={styles.image} source={{ uri: image.uri }} />
</TouchableHighlight>
);
})
}
</View>
</ScrollView>
);
}
出了个Warning: Each child in ar array or integrator should have a unique "key" prop
查了半天,在这里似乎得到答案 http://stackoverflow.com/questions/28329382/understanding-unique-keys-for-array-children-in-react-js
改为:
render() {
return (
<ScrollView style={styles.container}>
<View style={styles.imageGrid}>
{ this.state.images.map((image, i) => {//此处加了 ,i)
return (
<TouchableHighlight key={i} onPress={this.selectImage.bind(null, image.uri)}>//此处加了 key={i}
<Image style={styles.image} source={{ uri: image.uri }} />
</TouchableHighlight>
);
})
}
</View>
</ScrollView>
);
}
warning 消失,,,yeah!
相关文章推荐
- 【ReactNative】入门
- 最快让你上手ReactiveCocoa之基础篇
- ReactNativeiOS(三)开发零碎2 DatePickerIOS propType warning 4个
- 新的一年快开始了,学点新东西吧,从React开始(一)
- Angular2与React,前端的未来志向何方?
- 2015年终总结,忙碌与有所收获的一年,2016年继续努力!
- 为什么使用 React? Edit on GitHub
- 为什么使用 React? Edit on GitHub
- React 入门实例教程
- React 入门实例教程
- 一看就懂的ReactJs入门教程(精华版)
- 一看就懂的ReactJs入门教程(精华版)
- React-Native学习指南
- React-Native学习指南
- Reactor事件驱动的两种设计实现:面向对象 VS 函数式编程
- Reactor事件驱动的两种设计实现:面向对象 VS 函数式编程
- Reactor事件驱动的两种设计实现:面向对象 VS 函数式编程
- [React] Extracting Private React Components
- React-Native 知乎日报首页
- React Native 环境配置遇到的坑