You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native报错:Requested keys of a value that is not an object 求助

Fixing "Requested keys of a value that is not an object" in React Native ListView

Hey there, let's break down what's going on here and get your ListView working with those product objects.

First: You're passing the wrong data to createDataSource

The error points straight to this.createDataSource(this.props) — and that's likely the core issue. From your description, awaitingOrder is a specific array field inside your props, right? But you're passing the entire props object (which is an object, not an array) to the method.

When you manually test with ['hello','hello'], you're passing a valid array, which is why it works. But when you pass this.props, the ListView's DataSource tries to process an object like it's an array, which triggers that "Requested keys of a value that is not an object" error.

Fix this first: Change your call to:

this.createDataSource(this.props.awaitingOrder)

Second: Make sure createDataSource handles object arrays properly

If your current createDataSource looks like this (built for string arrays):

createDataSource(data) {
  return new ListView.DataSource({
    rowHasChanged: (r1, r2) => r1 !== r2,
  }).cloneWithRows(data);
}

It'll work for strings, but for objects, the rowHasChanged logic needs to check actual content (since two objects with identical data will have different references). Update it to compare the product field instead, plus add a safety net for invalid data:

createDataSource(data) {
  // Ensure we always pass an array to avoid type errors
  const safeData = Array.isArray(data) ? data : [];
  return new ListView.DataSource({
    rowHasChanged: (r1, r2) => r1.product !== r2.product,
  }).cloneWithRows(safeData);
}

Third: Update your renderRow to handle objects

If your renderRow was built for strings (like <Text>{rowData}</Text>), it'll just show [object Object] for your product entries. Update it to access the product property:

renderRow(rowData) {
  return <Text>{rowData.product}</Text>;
}

Quick recap of steps to test:

  • Swap this.props for this.props.awaitingOrder in your createDataSource call
  • Add the safety check and update rowHasChanged in createDataSource
  • Adjust renderRow to display the product field from each object

That should resolve the error and get your ListView rendering the product data correctly.

内容的提问来源于stack exchange,提问作者Sarmad Shah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 09:08:23