2016-02-15 20 views
9

Ad esempio, ho un elenco di città. Devo creare qualcosa come thisinput nativo con risposta automatica nativa

Come crearlo (per Android e IOS)? E dove dovrei conservarlo?

+0

abbiamo bisogno di ulteriori informazioni per aiutare. Hai i dati memorizzati localmente? Stai ottenendo i dati con una richiesta? Magari postare del codice in modo che possiamo vedere dove si trova il tuo problema. –

+0

I miei dati memorizzati nel file json. – zlFast

risposta

16

OK, quindi sulla base di poche informazioni che ci hai dato, ho cercato di fare un esempio veloce (nessun disegno a tutti) che si può trovare here

Ti farò fare la messa in piega.

Leggendo i dati dal file di figlio: controllare this

Il codice è il seguente:

'use strict'; 

var React = require('react-native'); 
var { 
    AppRegistry, 
    Component, 
    StyleSheet, 
    Text, 
    TextInput, 
    ListView, 
    View, 
} = React; 

var adresses = [ 
    { 
    street: "1 Martin Place", 
     city: "Sydney", 
    country: "Australia" 
    },{ 
    street: "1 Martin Street", 
     city: "Sydney", 
    country: "Australia" 
    } 
]; 

var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); 

class SampleApp extends Component { 
    constructor(props) { 
    super(props); 

    this.state = { 
     searchedAdresses: [] 
    }; 
    }; 

    searchedAdresses = (searchedText) => { 
    var searchedAdresses = adresses.filter(function(adress) { 
     return adress.street.toLowerCase().indexOf(searchedText.toLowerCase()) > -1; 
    }); 
    this.setState({searchedAdresses: searchedAdresses}); 
    }; 

    renderAdress = (adress) => { 
    return (
     <View> 
     <Text>{adress.street}, {adress.city}, {adress.country}</Text> 
     </View> 
    ); 
    }; 
    render() { 
    return (
     <View style={styles.container}> 
     <TextInput 
      style={styles.textinput} 
      onChangeText={this.searchedAdresses} 
      placeholder="Type your adress here" /> 
     <ListView 
        dataSource={ds.cloneWithRows(this.state.searchedAdresses)} 
      renderRow={this.renderAdress} /> 
     </View> 
    ); 
    }; 
} 

var styles = StyleSheet.create({ 
    container: { 
    flex: 1, 
    justifyContent: 'center', 
    alignItems: 'center', 
    backgroundColor: '#FFFFFF', 
    }, 
    textinput: { 
    marginTop: 30, 
    backgroundColor: '#DDDDDD', 
    height: 40, 
    width: 200 
    } 
}); 

AppRegistry.registerComponent('SampleApp',() => SampleApp); 
+0

grazie per questa soluzione! – mvdb

+3

Non è più disponibile ... – Gp2mv3

+0

Il collegamento è interrotto. – dhuma1981

Problemi correlati