有没有办法动态渲染具有可变宽度的反应组件?
我正在使用 JavaScript 开发先来先服务 CPU 调度程序。我面临的问题是,由于某种原因,我的甘特图可视化组件在应该的时候(计算完成时)没有呈现。然而,当我更改代码并且计算完成时,该组件确实会呈现。
似乎渲染是随机的,因为有时当我添加 console.log(processes) 来查看在将数据映射到进程之前发生的情况时,1)数据在那里,2)它会随机渲染。
甘特图组件的代码:
export default function GanttChart({processes}) {
return (
<div className="chart-area">
<div className="gantt-chart">
{processes.map((process) => (
<>
<div key={process.processName} className="process" style={{ width: (parseInt(process.burstTime, 10)) + "%" }}>{process.processName}</div>
</>
))}
</div>
</div>
)
}
我试图在 calcTurnAroundWaitingTime() 函数执行后渲染此组件,并且每个“进程”的宽度基于该进程的burstTime:
处理 FirstComeFirstServe 算法的函数:
function handleFCFS(e){
e.preventDefault();
// Pushing the process data from the form to the process array for each process
processData.forEach(process => {
processes.push(process);
});
// Error checking if there are no processes to process by seeing if the first processName === null
if (!processes[0].processName){
alert("Nothing to process");
return;
}
processes.join(); // Joining the array of objects together as a string separated by ,
processes.sort(orderLeastGreatest); // Sorting the string by calling the compare function that compares the objects arrival times
// Calculating completion time
calcCompletionTime(processes);
// Calculating turnaround time and waiting time
calcTurnAroundWaitingTime(processes);
I am working on a First Come First Serve CPU scheduler with JavaScript. The problem I am facing is that for some reason my component for the gantt-chart visualization does not render when it is supposed to (When the calculations are completed). The component however does render when I make a change to the code and the calculations have completed.
It seems as though the rendering is at random as sometimes when I add in a console.log(processes) to see what is happening right before I map the data to a process, 1) the data is there and 2) It randomly will render.
Code for Gantt-Chart component:
export default function GanttChart({processes}) {
return (
<div className="chart-area">
<div className="gantt-chart">
{processes.map((process) => (
<>
<div key={process.processName} className="process" style={{ width: (parseInt(process.burstTime, 10)) + "%" }}>{process.processName}</div>
</>
))}
</div>
</div>
)
}
I'm trying to have this component to render after calcTurnAroundWaitingTime() function executes and the width of each "process" is based upon the burstTime of that process:
Function that handles the FirstComeFirstServe Algorithm:
function handleFCFS(e){
e.preventDefault();
// Pushing the process data from the form to the process array for each process
processData.forEach(process => {
processes.push(process);
});
// Error checking if there are no processes to process by seeing if the first processName === null
if (!processes[0].processName){
alert("Nothing to process");
return;
}
processes.join(); // Joining the array of objects together as a string separated by ,
processes.sort(orderLeastGreatest); // Sorting the string by calling the compare function that compares the objects arrival times
// Calculating completion time
calcCompletionTime(processes);
// Calculating turnaround time and waiting time
calcTurnAroundWaitingTime(processes);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论