javascript - 行样式 React Native
问题描述
嘿,我是 React Native 的新手,目前我正在尝试从 API 渲染自定义单选按钮并将其制成 2x2 网格。按钮渲染成功,但它们没有渲染到 2x2 网格,我使用 push 方法制作行和列,似乎按钮没有正确传递到行和列。有什么我做错了吗?
{
this.props.activities && this.props.activities.map((val, idx) => {
let { id, activity, status } = val;
let buttons = [];
if (idx < (this.props.activities.length - 1))
buttons.push(
<RadioButton
key={id}
value={activity}
element={<Image source={img.findActivityButton(id, false)} style={{marginHorizontal: normalize(10), marginVertical: normalize(10)}} />}
selectedElement={<Image source={img.findActivityButton(id, true)} style={{marginHorizontal: normalize(10), marginVertical: normalize(10)}} />}
onPress={() => this.changeSelection(id)}
selected={this.state.selectedButton === id}
/>
);
var rows = [], columns = [];
var i = 0;
buttons.forEach((id, idx) => {
rows.push(id);
i++;
if (i === 2 || idx === buttons.length - 1) { //max buttons per row
i = 0;
columns.push(
<View key={idx} style={{ flex: 1, flexDirection: 'row' }}>
{rows}
</View>
);
rows = [];
i = 0;
}
});
return (
<View style={{ flex: 1, margin: normalize(20) }}>
{columns}
</View>
);
})
}
更新
它实际上确实传递给了行和列,这只是样式问题,我很困惑如何设置它的样式。我敢肯定,在这需要样式的部分,有没有样式呢?
columns.push(
<View key = { idx} style = {{flex: 1, flexDirection: 'row'}}>
{
rows
}
</View>
);
这是我的代码的结果
解决方案
推荐阅读
- wpf - 如何使用 wpf 创建多语言应用程序
- json - 我有一个列表列表
id = ["abc","abc","abc"],我如何解析成 json 字符串,因为我可以在颤振中传入 http.post(body) - vba - Selection.Find 通过文档与它应该找到的文本不匹配
- rasa - 为什么 rasa init 给出错误:无法识别
- r - 如何在R中的数据框列表中按第二行从最大到最小对列进行水平排序?
- machine-learning - Tidymodels(在 R 中使用 10 倍交叉验证拟合袋装树):x Fold01:模型:错误:输入必须是向量,而不是 NULL
- mysql - 在MYSQL中用空格分割字符串
- asp.net-core - 如何在 ASP.NET Core 3.1 中重新加载动态配置的重写选项
- python - 如何在 tkinter 文本框中使用带有 html 标签的文本,或更改它以使其在 tkinter 标签中工作?
- javascript - 重叠元素中的 onClick 事件传播