2017-08-24 19 views
0

私は関数からリストビューを更新しようとしていますが、現在は更新されていません。ここに完全なソースコードがあります。ListViewデータソースが更新されていません - リアクションネイティブ

も私が間違って

 import React, { Component } from 'react'; 
    import { 
     AppRegistry, 
     ListView, 
     TextView, 
     Text, 
     View 
    } from 'react-native'; 


    const ds = new ListView.DataSource({ rowHasChanged: (row1, row2) => row1 != row2 }); 

    var myarray = []; 
    export default class filesix extends Component { 
     constructor() { 
     super(); 
     this.state = { 
      dataSource: ds.cloneWithRows(myarray), 
     }; 
     console.log(`ds const =${myarray}`); 
     } 


     componentDidMount() { 
     myarray = ['11', '22']; 
     console.log(myarray); 
     this.setState = ({ 
      datasource: this.state.dataSource.cloneWithRows(myarray), 
     }); 
     this.prepareDataSource(); 
     console.log('this componentDidMount'); 
     } 

     prepareDataSource() {  
     myarray = ['11', '22']; 
     console.log(myarray); 
     } 

     renderRow(rowData) { 
     return <Text>{JSON.stringify(rowData)}</Text> 
     } 

     render() { 
     return (
      <View style={{ flex: 1, borderWidth: 2 }}> 
      <ListView 
       enableEmptySections={true} 
       dataSource={this.state.dataSource} 
       renderRow={this.renderRow} 
      /> 
      </View> 
     ); 
     } 
    } 

    AppRegistry.registerComponent('filesix',() => filesix); 

をやって何をすることを明記してください私はすでに値を更新するために、私の一日を過ごしたが、ない運が、私の理解を修正していないしてください。

+0

更新されていないものはありますか?それらは2つの行をレンダリングしていますか? –

+0

いいえ2行を表示しません –

答えて

1

componentDidMountには、タイプミスがあります。 datasourceに状態が設定されていますが、ListViewはdataSourceを使用しています。

+0

他に何かを追加すると冗長になります。 –

関連する問題