I'm having trouble getting a component to render within .map
render: function() {
var self = this;
var ListItems = this.props.data.map(function(data){
self.props.fields.forEach(function(field, i) {
if (field.fieldKey in data) {
console.info(field.fieldKey + ': ' + data[field.fieldKey]);
return (<ListItem {...data} key={'field-' + i}/>)
} else {
console.error(field.fieldKey + " doesn't exist. Please make sure you match your 'fieldKey' to an existing column in your data table");
}
});
});
return <tr onDoubleClick={this.handleEditRow} onClick={this.handleSelectRow}>
{ListItems}
<td className="text-center">
<span className="btn"><input type="checkbox" ref="deleteCheckbox" checked={this.props.checked} onChange={this.handleDeleteChange}/></span>
<a className="btn" onClick={this.handleDeleteRow} title="Delete this Item"><i className="md md-close"></i></a>
</td>
</tr>
},
So my ListItem doesn't show at all. If I move it under the first loop, it shows fine. Can anyone tell me what I'm doing wrong?
UPDATES
JSON DATA
So, I'm creating a list view. Basically, each item under data has a fields setting attached via the fieldKey
So the plan is to spit out the data, but use the configuration options under fields to format the list view. i.e. fieldKey is a dropdown, it's dataSource is message yada yada.
Name(data: test 1) (fields: is dropdown) | calling_gt(data: 123456) (fields: is text) | op_code (data: 5678) (fields: is dropdown)
this.props.data.mapyou didn't return anything from this. Thisreturn (<ListItem {...data} key={'field-' + i}/>)is inself.props.fields.forEach, not in map scope.undefined.console.log, and then rewrite asvar xxx = self.props.fields.forEach...., thenconsole.log(xxx)to see that it did returns nothing.