英文:
How to pass the job.id from a loop to the payload for storing new comments on the comment table when a user comments on a specific job?
问题
我一直在尝试解决一个问题,我需要从循环中传递item.id
值到有效载荷中,以便在用户评论特定工作时将新评论存储在评论表中。尽管尝试了各种解决方案,但我无法取得进展。
<div class="posts-section">
<div class="post-bar">
<div class="post_topbar">
<div class="usy-dt">
<img src={asset('small', item.users.profil_picture)} alt="" />
<div class="usy-name">
<h3 key={index}>{item.users.name}</h3>
<span>
<img src="images/clock.png" alt="" />
{time(item.created_at)}
{/* { time(item.created_at)} */}
{/* {timePassed} */}
</span>
</div>
</div>
<Form onSubmit={handleSubmit} type="submit">
<InputGroup className="mb-3 comment-sect">
<InputGroup.Text id="inputGroup-sizing-default">
<Image src={asset('small', currentUser.profil_picture)} rounded className="profil-comment" />
</InputGroup.Text>
<Form.Control
as="textarea"
rows={1}
onChange={handleTextareaChange}
aria-label="Default"
aria-describedby="inputGroup-sizing-default"
// className={textareaValue.trim() !== '' ? 'filled' : ''}
/>
<div
className={`comment-send-container ${textareaValue.trim() !== '' ? 'active-icon' : 'disable-icon'}`}
onClick={handleSubmit}
value={textareaValue}
>
<FontAwesomeIcon icon={faPaperPlane} className="comment-send-icon" />
</div>
</InputGroup>
</Form>
</div>
</div>
</div>
const handleSubmit = e => {
e.preventDefault()
const payload = {
comment: textareaValue,
user: currentUser.id,
}
console.log(payload)
}
英文:
I have been attempting to solve a problem where I need to pass the item.id value from a loop to the payload in order to store new comments on the comment table when a user comments on a specific job. Despite trying various solutions, I have been unable to make progress
<div class="posts-section">
<div class="post-bar">
<div class="post_topbar">
<div class="usy-dt">
<img src={asset('small', item.users.profil_picture)} alt="" />
<div class="usy-name">
<h3 key={index}>{item.users.name}</h3>
<span>
<img src="images/clock.png" alt="" />
{time(item.created_at)}
{/* { time(item.created_at)} */}
{/* {timePassed} */}
</span>
</div>
</div>
<Form onSubmit={handleSubmit} type="submit">
<InputGroup className="mb-3 comment-sect">
<InputGroup.Text id="inputGroup-sizing-default">
<Image src={asset('small', currentUser.profil_picture)} rounded className="profil-comment" />
</InputGroup.Text>
<Form.Control
as="textarea"
rows={1}
onChange={handleTextareaChange}
aria-label="Default"
aria-describedby="inputGroup-sizing-default"
// className={textareaValue.trim() !== '' ? 'filled' : ''}
/>
<div
className={`comment-send-container ${textareaValue.trim() !== '' ? 'active-icon' : 'disable-icon'}`}
onClick={handleSubmit}
value={textareaValue}
>
<FontAwesomeIcon icon={faPaperPlane} className="comment-send-icon" />
</div>
</InputGroup>
</Form>
const handleSubmit = e => {
e.preventDefault()
const payload = {
comment: textareaValue,
user: currentUser.id,
}
console.log(payload)
}
答案1
得分: 0
<Form onSubmit={{(e) => handleSubmit(e,item)}} type="submit">
这部分代码将在你的函数中获取到该项
const handleSubmit=(e,item)=>{
e.preventDefault();
const payload={
// jobId : item.id **添加你的键**
comment:textareaValue,
user:currentUser.id,
}
console.log(payload);
}
英文:
<Form onSubmit={{(e) => handleSubmit(e,item)}} type="submit">
This item you can get in your function
const handleSubmit=(e,item)=>{
e.preventDefault();
const payload={
// jobId : item.id **Add your key**
comment:textareaValue,
user:currentUser.id,
}
console.log(payload);
}
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论