【发布时间】:2015-06-21 22:15:51
【问题描述】:
刚开始使用 ReactJS,我正在寻找最有效的代码来在表结构中显示下面的数组,如“渲染”部分所述。我一直在使用 .map 来遍历用户/按钮对象,但还没有成功。
在下面的代码示例中,我想获取 userData 数组并将内容显示在单独的行中(html 表格格式)即。
Joe,Smith,[Click 1A],[Click2B] //'Click XX' 是按钮
玛丽,墨菲,[点击 2A],[点击 2B]
我怎样才能做到这一点?
谢谢
var MyButton = require('./mybutton.js');
var userData =[{
userButtons: [
[{user: [{ id: 1, lastName: 'Smith', firstName: 'Joe',
buttons: [
{button:[{ id:0, value: "Click 1A" enabled:1}]},
{button:[{ id:1, value: "Click 1B" enabled:1}]}
]
}]}],
[{user: [{ id: 1, lastName: 'Murphy', firstName: 'Mary',
buttons: [
{button:[{ id:0, value: "Click 2A" enabled:1}]},
{button:[{ id:1, value: "Click 2B" enabled:1}]}
]
}]
}]
]}];
var DisplayData = React.createClass({
render: function() {
// render userButtons in a table with data using <MyButton> ie.
// <table>
// <tr><td>Joe</td><td>Smith</td><td>[Click 1A]</td><td>[Click 2A]</td</tr>
// <tr><td>Mary</td><td>Murphy</td><td>[Click 2B]</td><td>[Click 2B]</td></tr>
// </table>
}
}
});
React.render(
<DisplayData tArr = {userData} />
, document.getElementById('content')
);
// mybutton.js
var React = require('react');
module.exports = React.createClass({
render: function() {
return (
<button>{this.props.value}</button>
)
}
});
标签: javascript arrays components reactjs