Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get DataSource length in react-native?

How do I get the DataSource's length of a ListView?

Suppose I have the following declaration:

const ds = new ListView.DataSource({ rowHasChanged });
...
someObjectsDs = ds.cloneWithRows(someObjectsArray);

I've tried someObjects.length but this returns me undefined.

like image 571
Luiz Avatar asked May 15 '17 21:05

Luiz


2 Answers

You can view the amount of rows to be rendered by calling

someObjectsDs.getRowCount()

Official documentation

like image 200
NiFi Avatar answered Nov 15 '22 04:11

NiFi


You can either dig into the datasource object to find the data and grab the length or you can set the data as a property of the component and refer to that:

this.someObjectsArray = someObjectsArray;
someObjectsDs = ds.cloneWithRows(this.someObjectsArray);

Now you will be able to do this.someObjectsArray.length, just make sure you're updating this variable anytime you're updating the datasource.

like image 33
Matt Aft Avatar answered Nov 15 '22 04:11

Matt Aft