我正在尝试通过在方法中返回一个方法以在React Native中用Text元素填充View元素:
<视图> {this._getCategories(item)} 视图>
_getCategories方法在使用item参数检索正确的数据后返回Text元素。简化版本如下:
_getCategories = item => {
names = 'some string';
console.log(names); //this logs the correct string
return <Text style={styles.categories}>{names}</Text>;
};
如果我在View元素中使用{String(names)},则Text元素不会出现在应用程序中,并且显示为undefined。
答案 0 :(得分:1)
尝试{String(names)}
和{names}
都可以。检索方法可能有问题。