例如,我想显示姓名列表。所以我想做这样的事情:
var returnValue;
for (eachName of _names) {
returnValue += (
<TouchableHighlight
onPress={() => this._onPressButton}>
<Text>
{eachName}
</Text>
</TouchableHighlight>);
}
return returnValue;
但是,这是无效的。这让我想到了我的问题:如何在 React Native 中连接动态数量的 JSX 组件。
最佳答案
当我询问 stackoverflow 时,我很快就弄清楚了。代码需要放入数组中:
var returnValue = [];
for (var i = 0; i < _names.length; i++) {
returnValue.push(
<TouchableHighlight onPress={() => this._onPressButton}>
<Text>
{_names[i]}
</Text>
</TouchableHighlight>);
}
return returnValue;
这里还有更多信息:http://facebook.github.io/react/docs/multiple-components.html#dynamic-children
关于react-native - 如何在 React Native 中连接 JSX 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29970434/