ListView不更新

编程入门 行业动态 更新时间:2024-10-26 17:31:50
ListView不更新 - ListViewDataSource.js中的错误(ListView not updating – error in ListViewDataSource.js)

我目前正在使用React Native框架显示iOS应用程序。 为了允许用户选择可用的蓝牙LE设备,我使用RefreshableListView(NPM包:react-native-refreshable-listview)组件,该组件使用React提供的ListView组件。 当我第二次使用该列表(我的应用程序具有离线模式)时,我将其放入单独的组件中并使用属性传递可用设备。 组件在方法componentWillReceiveProps: function(newProperties) ,如下所示。

componentWillReceiveProps: function(newProperties) { if (newProperties.devices !== undefined) { if (newProperties.devices.length > 0) { alert("length: " + newProperties.devices.length); // the expected result is shown by this statement this.setState ( { dataSource: this.state.dataSource.cloneWithRows(newProperties.discoveredDevices) } ); } } }

问题是由于以下错误(使用Google Chrome的调试工具捕获),列表视图未更新:

Uncaught TypeError: Cannot convert undefined or null to object ListViewDataSource.js:202

为避免此错误,我尝试初始化数组,如下所示:

componentDidMount: function() { this.setState ( { dataSource: this.state.dataSource.cloneWithRows(new Array()) } ); }

但是,这还没有解决问题。 使用静态数据初始化数组(由方法componentDidMount )也不能修复错误。

我很感激任何建议。 提前致谢!

I'm currently displaying an iOS application using the React Native framework. For allowing the user to choose an available Bluetooth LE device I use a RefreshableListView (NPM package: react-native-refreshable-listview) component which uses the ListView component supplied by React. As I use the list a second time (my application has an offline mode) I put it into a separate component and pass the available devices in using properties. The component is updated in the method componentWillReceiveProps: function(newProperties), as shown below.

componentWillReceiveProps: function(newProperties) { if (newProperties.devices !== undefined) { if (newProperties.devices.length > 0) { alert("length: " + newProperties.devices.length); // the expected result is shown by this statement this.setState ( { dataSource: this.state.dataSource.cloneWithRows(newProperties.discoveredDevices) } ); } } }

The problem is that the list view is not updated due to the following error (captured using Google Chrome's debugging tool):

Uncaught TypeError: Cannot convert undefined or null to object ListViewDataSource.js:202

For avoiding this error I have tried to initialize the array as shown below:

componentDidMount: function() { this.setState ( { dataSource: this.state.dataSource.cloneWithRows(new Array()) } ); }

However, this has not solved the issue. Initializing the array with static data (done by the method componentDidMount) does not fix the error too.

I appreciate any advice. Thanks in advance!

最满意答案

React Native的最新版本(0.5.0 RC 0)解决了这个问题。

The latest version (0.5.0 RC 0) of React Native solved this issue.

更多推荐

本文发布于:2023-07-31 22:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1348987.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ListView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!