How to get DataSource length in native-native?

How to get DataSource length in ListView?

Suppose I have the following declaration:

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

I tried someObjects.length, but it brings me back undefined.

+4
source share
2 answers

You can view the number of rows to display by calling

someObjectsDs.getRowCount()

Official documentation

+6
source

You can either dig into the data source object to find the data and grab the length, or you can set the data as a component property and refer to this:

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

Now you can do it this.someObjectsArray.length, just be sure to update this variable anytime you update the data source.

+1
source

Source: https://habr.com/ru/post/1677207/


All Articles