我正在使用I18在我的应用上支持多语言。这是我的代码
class MyClass extends Component {
constructor(props) {
super(props);
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.state = {
dataSource: ds.cloneWithRows(data.apps),
};
}
render() {
const language = this.props.language
alert(language);
return (
<View style={styles.container}>
<Text> {I18n.t('settings.title')} </Text> // This get updated
<ListView contentContainerStyle={styles.list}
dataSource={this.state.dataSource}
renderRow={(rowData) =>
<Text> {I18n.t('settings.title')} </Text> // Not updated
<Text> rowData.[language] </Text> // Not updated
问题在于,当切换语言时,调用渲染并弹出新语言,但返回的值不会改变。