React native 在react native中创建对象
我正试图将React native 在react native中创建对象,react-native,React Native,我正试图将noteText保存在文本中,但这成了一个问题。我想创建一个具有相同属性的对象:名称、日期、注释,并且只显示名称和日期。另外,我想在创建注释时将其映射到数组中。像这样 let notes = this.state.noteArray.map((val, key)=>{ return <Note key={key} keyval={key} val={val} deleteMethod={()=>this.deleteNo
noteText
保存在文本中,但这成了一个问题。我想创建一个具有相同属性的对象:名称、日期、注释,并且只显示名称和日期。另外,我想在创建注释时将其映射到数组中。像这样
let notes = this.state.noteArray.map((val, key)=>{
return <Note key={key} keyval={key} val={val}
deleteMethod={()=>this.deleteNote(key)} openNote={()=>this.openNote(key)}/>
});
这是课堂笔记:
import React, { Component } from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
TouchableWithoutFeedback,
} from 'react-native';
export default class Note extends Component {
render() {
return (
<TouchableWithoutFeedback key={this.props.keyval} onPress={this.props.openNote}>
<View style={styles.note}>
<Text style={styles.noteDate}>{this.props.val.noteNumber}</Text>
<Text style={styles.noteDate}>{this.props.val.date}</Text>
<Text style={styles.noteText}>{this.props.val.note}</Text>
<TouchableOpacity onPress={this.props.deleteMethod} style={styles.noteDelete}>
<Text style={styles.noteDeleteText}>Del</Text>
</TouchableOpacity>
</View>
</TouchableWithoutFeedback>
);
}
}
const styles = StyleSheet.create({
note: {
position: 'relative',
padding: 20,
backgroundColor:'#fff',
paddingRight: 100,
borderLeftWidth:1,
borderLeftColor: '#000',
borderRightWidth:1,
borderRightColor: '#000',
borderBottomWidth:1,
borderBottomColor: '#000'
},
noteDate:{
paddingLeft: 20,
borderLeftWidth: 10,
borderLeftColor: '#0000FF'
},
noteText: {
paddingLeft: 20,
borderLeftWidth: 10,
borderLeftColor: '#0000FF',
opacity: 0,
},
noteDelete: {
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#2980b9',
padding: 10,
top: 10,
bottom: 10,
right: 10
},
noteDeleteText: {
color: 'white'
},
});
import React,{Component}来自'React';
进口{
看法
文本,
样式表,
可触摸不透明度,
可触摸且无反馈,
}从“反应本机”;
导出默认类注释扩展组件{
render(){
返回(
{this.props.val.noteNumber}
{this.props.val.date}
{this.props.val.note}
德尔
);
}
}
const styles=StyleSheet.create({
注:{
位置:'相对',
填充:20,
背景颜色:“#fff”,
paddingRight:100,
borderLeftWidth:1,
borderLeftColor:“#000”,
borderRightWidth:1,
borderRightColor:“#000”,
边界宽度:1,
borderBottomColor:“#000”
},
注日期:{
paddingLeft:20,
边线宽度:10,
borderLeftColor:“#0000FF”
},
注文本:{
paddingLeft:20,
边线宽度:10,
borderLeftColor:“#0000FF”,
不透明度:0,
},
注删除:{
位置:'绝对',
为内容辩护:“中心”,
对齐项目:“居中”,
背景颜色:“#2980b9”,
填充:10,
前10名,
底部:10,
右:10
},
注删除文本:{
颜色:“白色”
},
});
以下是我研究的示例:
import React, { Component } from "react";
class Counter extends Component {
state = { counter: this.props.startsWith };
...
}
我使用的不是计数器
,而是注释
本身。您使用的导航库是什么?您想发布所有的类以了解大致情况吗?这有点难以解释。如果你认为这会有帮助,那就走吧。事实上,我已经解决了这个问题!:)对不起,浪费了你的时间!:/在此处发布您的解决方案,以便其他人稍后可以咨询
import React, { Component } from "react";
class Counter extends Component {
state = { counter: this.props.startsWith };
...
}