Matt The Ninja Matt The Ninja - 1 year ago 199
React JSX Question

React Native - ListView, CloneWithRow with object not array

I am pulling some data from a webservice.
On the calls that are returning JSON arrays i am able to do the following just fine.

dataSource: this.state.dataSource.cloneWithRows(val)
.catch((error) => console.log('callapi:'+ JSON.stringify(error)));

For instance the following data would work perfectly..


However when i try to feed object with keys like below it doesn't like it.

"SKU1": {"level":11, "description":"This is SKU 1"},
"SKU2": {"level":22, "description":"This is SKU 2"},
"SKU3": {"level":33, "description":"This is SKU 3"}

Can ListView handle object with keys or do i need to loop and amend this data on receipt before I can pass it to ListView?

If i have to amend it, without looping it, does any framework offer a quick way to achieve this?

Answer Source

You can not give object to cloneWithRows. you can convert to array or you can use cloneWithRowsAndSections. It accepts object and you can render sectionHeader aswell.

Check documentation ->

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download