javascript - React Native - ListView,CloneWithRow,对象不是数组

标签 javascript reactjs react-native

我正在从网络服务中提取一些数据。 在返回 JSON 数组的调用中,我可以很好地执行以下操作。

 WebServiceHandler.get('http:/api.local/stock',{},{)
         .then((val)=>{
           this.setState({
             dataSource: this.state.dataSource.cloneWithRows(val)
           })
         })
         .catch((error) => console.log('callapi:'+ JSON.stringify(error)));
  }

例如以下数据将完美地工作..

[
    "SKU1",
    "SKU2",
    "SKU3"
]

但是,当我尝试使用如下键输入对象时,它不喜欢它。

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

ListView 可以处理带键的对象吗?还是我需要循环并修改收到的数据才能将其传递给 ListView?

如果我必须修改它,而不是循环它,是否有任何框架提供了实现此目的的快速方法?

最佳答案

你不能给 cloneWithRows 对象。您可以转换为数组,也可以使用 cloneWithRowsAndSections。它接受对象,您也可以呈现 sectionHeader。

检查文档 -> https://facebook.github.io/react-native/docs/listviewdatasource.html

关于javascript - React Native - ListView,CloneWithRow,对象不是数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40389592/

相关文章:

javascript - HTML5/Javascript - 我的用户触发的 Canvas 动画断断续续

reactjs - react native / enzyme : mount throws "unknown props" on native elements

javascript - React 项目中的 Bootstrap 需要 jQuery

javascript - 在 react-native 中打开路由中未指定的 DeepLink

javascript - 此代码的工作原理 .html(_.template()({ }) )

javascript - 创建指向在页面上运行 Javascript 函数的网页的链接

javascript - 如何在 javascript 函数中定义全局变量并在其外部访问它?

reactjs - Meteor React Komposer : Execute Component Constructor AFTER ready subscription

reactjs - 如何在 React-Native 的 Navigator 的多个场景之间共享状态

javascript - 在 react 中更改高阶组件中的 Prop