我目前正在使用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:202For 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.
更多推荐
发布评论