[英]Initialize empty array of objects in react native
I want to create an empty array object in react native that I want to populate with data from a sqlite table.我想在本机反应中创建一个空数组 object,我想用 sqlite 表中的数据填充它。 I've searched on google but I only get responses like
this.state={}
or this.state = { newArr: [] }
, but I want to create an empty array of objects similar to const [{ID:'', Name:'', Email:''}]
.我在谷歌上搜索过,但我只得到类似
this.state={}
或this.state = { newArr: [] }
的响应,但我想创建一个类似于const [{ID:'', Name:'', Email:''}]
的空对象数组const [{ID:'', Name:'', Email:''}]
。
any idea how I can achieve this?知道我怎么能做到这一点吗?
Ideally, newArr=[] works.理想情况下, newArr=[] 有效。 However if you want to make it something like that [{ID:'', Name:'', Email:''}].
但是,如果你想让它像 [{ID:'', Name:'', Email:''}]。 It is also possible.
这也是可能的。 Let me share some example.
让我分享一些例子。
const initialArr = [{ID:'', Name:'', Email:''}];
class YOURCOMPONENT extends React.Component{
constructor(props){
super(props);
this.state = {
newArr:initialArr,
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.