在本机反应中初始化空对象数组
Initialize empty array of objects in react native
我想在 React Native 中创建一个空数组对象,我想用来自 sqlite 的数据填充它 table。我在 google 上搜索过,但只收到 this.state={}
或
this.state = { newArr: [] }
,但我想创建一个空的对象数组,类似于
const [{ID:'', Name:'', Email:''}]
.
知道如何实现吗?
理想情况下,newArr=[] 有效。但是,如果你想让它成为类似 [{ID:'', Name:'', Email:''}] 的东西。这也是可能的。让我分享一些例子。
const initialArr = [{ID:'', Name:'', Email:''}];
class YOURCOMPONENT extends React.Component{
constructor(props){
super(props);
this.state = {
newArr:initialArr,
}
}
我想在 React Native 中创建一个空数组对象,我想用来自 sqlite 的数据填充它 table。我在 google 上搜索过,但只收到 this.state={}
或
this.state = { newArr: [] }
,但我想创建一个空的对象数组,类似于
const [{ID:'', Name:'', Email:''}]
.
知道如何实现吗?
理想情况下,newArr=[] 有效。但是,如果你想让它成为类似 [{ID:'', Name:'', Email:''}] 的东西。这也是可能的。让我分享一些例子。
const initialArr = [{ID:'', Name:'', Email:''}];
class YOURCOMPONENT extends React.Component{
constructor(props){
super(props);
this.state = {
newArr:initialArr,
}
}