I am trying to render a set of <div> </div>
based on the items that are in an object but I don't want to have to specify the name of the items in the object in order to display them.
In the example below I want the WorkObjectID and WorkObjectVal to be dynamic and not static. If I add the tempObject to the object it will not be displayed when the data is rendered because I did not define it in the miniTable.
I would like to specify which ones will be shown by sending them if possible in the var WORKOBJECTSVALS = {}
.
var WORKOBJECTS = [ {
WorkObjectID: "1", WorkObjectVal: "First",
TempObject1: "55", TempObject2: "Denied"
},
{
WorkObjectID: "2", WorkObjectVal: "Second",
TempObject1: "110", TempObject2: "Allowed"
}];
var WORKOBJECTSVALS = {"WorkObjectID", "WorkObjectVal", "TempObject1" };
render: function () {
var miniTable = this.state.WORKOBJECTS.map(function(val) {
return (
<div> {val.WorkObjectID} </div>
<div> {val.WorkObjectVal} </div>
);
});
return(
{miniTable}
);
}
In the example above I would like the TempObject1
to be displayed but not the TempObject2
. If I decide in the future that I would like the TempObject2
to be added into the div I would only need to add it to WORKOBJECTSVALS
, how can I do this?