Api Data :
{
"Status": 1000,
"Properties": {
"ClipName": "Clip1",
"Upcounter": "15:33:44:33",
"DownCounter": "16:33:44:33",
"ChannelName": "Channel1",
"StartTimeCode": "00:00:00:00",
"PlayerName": "Vtr1",
"Duration": "12:00:00:01"
}
}
{
"Status": 1001,
"Properties": {
"ClipName": "",
"Upcounter": "",
"DownCounter": "",
"ChannelName": "",
"StartTimeCode": "",
"PlayerName": "",
"Duration": ""
}
}
{
"Status": 1000,
"Properties": {
"ClipName": "Clip3",
"Upcounter": "12:33:44:33",
"DownCounter": "12:33:44:33",
"ChannelName": "Channel3",
"StartTimeCode": "00:00:00:00",
"PlayerName": "Vtr3",
"Duration": "12:00:00:01"
}
}
{
"Status": 1000,
"Properties": {
"ClipName": "Clip4",
"Upcounter": "18:16:27:361",
"DownCounter": "18:16:27:361",
"ChannelName": "Channel4",
"StartTimeCode": "00:00:00:00",
"PlayerName": "Vtr4",
"Duration": "12:00:00:01"
}
}
I have more than 4 data in api but only 1 upcounter is showing how i can shoe more upcounter in table row
CODE :
const [setdata, fetchdata] = useState([]);
const [data,setData] = useState([]);
useEffect(() => {
getfetchData();
}, [])
useEffect(() => {
setdata.forEach(function (val) {
getPostData(val.Player, val.IP, val.Port, val.ChannelName);
});
}, [setdata])
function getfetchData() {
axios.get("http://localhost:9763/api/getPlayers",
{
headers: {
"accepts": "application/json",
'Access-Control-Allow-Origin': '*',
},
auth: {
username: 'admin',
password: 'password'
},
}).then(response => {
//console.log(response.data)
//console.log([...Object.values(response.data).flat()]);
fetchdata([...Object.values(response.data).flat()]);
}).catch(error => {
console.log(error);
});
}
// Post Data
function getPostData(Player, IP, Port, channelName) {
var data = {
PlayerName: Player,
ChannelName: channelName,
Port: Port,
IpAddress: IP
}
axios({
method: 'post',
url: 'http://localhost:9763/api/getPlayerStatus',
data,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
auth: {
username: 'admin',
password: 'password'
}
}).then(response => {
console.log([response.data]);
setData([response.data]);
}).catch(error => {
console.log("Error In Post Data", error);
});
}
return (
<div>
<div className="container-fluid pt-2">
<table className=" table-borderless text-center tablemainBody">
<thead>
<tr className="title" >
{
Object.values(setdata).map((val) => {
return (
<th key={val.Player} > <AiOutlineCheck style={{ color: 'black', backgroundColor: "#41fc00", borderRadius: "25px" }} />
{val.ChannelName} </th>
)
})
}
</tr>
</thead>
<tbody>
<tr>
{
data.map((val, index) => {
// console.log("Inside Map", val);
return (
<td key={index}>{val.Properties.DownCounter} </td>
)
})
}
</tr>
</tbody>
</table> </div>
</div >
);
}
Only one api data is fetch/ Display in table row i want more data to show but not able to show that and i also want to use a setInterval but when i use setInterval every pervious data in api is showing in one table row (when i refresh the page itself change in 1 value currently its showing 4 value)