admin管理员组文章数量:1399119
Want to render buttons Based upon the json { "ActionType" : [{ "Field" : "Button", "FieldText" : "No", "FieldAction" : "this.getCellNumber('no')", "style":"" },{ "Field" : "Button", "FieldText" : "No", "FieldAction" : "this.getCellNumber('yes')", "style":"" }] }
How can I loop it in a render function to get number of buttons in a view
render(){
return(
<View style={this.styles.ButtonValContainer}>
</View>
);
}
Want to render buttons Based upon the json { "ActionType" : [{ "Field" : "Button", "FieldText" : "No", "FieldAction" : "this.getCellNumber('no')", "style":"" },{ "Field" : "Button", "FieldText" : "No", "FieldAction" : "this.getCellNumber('yes')", "style":"" }] }
How can I loop it in a render function to get number of buttons in a view
render(){
return(
<View style={this.styles.ButtonValContainer}>
</View>
);
}
Share
Improve this question
edited May 7, 2016 at 15:36
Nilesh
asked May 7, 2016 at 15:28
NileshNilesh
1671 gold badge4 silver badges17 bronze badges
2 Answers
Reset to default 6in react you can easily collect an array of elements for rendering.
const buttons = [
{
text: 'button one',
action: () => console.log('pressed button one'),
},
{
text: 'button two',
action: () => console.log('pressed button two')
}
];
....
// react class definition
// ...
// assuming `Button` is a defined class in scope.
render() {
const renderedButtons = buttons.map(b => {
return <Button key={b.text} text={b.text} onPress={b.action} />;
});
return (
<View>
{renderedButtons}
</View>
)
}
hope that helps a bit.
You can iterate through a list and return a ponent in the callback. The only requirement is that the returned ponent has an key
attribute, which is used by React internally when rerendering (so that it knows what to remove/shift/update etc)
render() {
return(
<Wrapper>
{items.forEach(function(item) {
return (
<View style={this.styles.ButtonValContainer} key={'UNIQUE_KEY_HERE'}>
...
</View>
);
})}
</Wrapper>
);
}
Here's some more info: https://facebook.github.io/react/docs/multiple-ponents.html
本文标签: javascriptRendering Multiple Buttons in a View react native programmaticallyStack Overflow
版权声明:本文标题:javascript - Rendering Multiple Buttons in a View react native programmatically - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744199327a2594890.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论