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?

huangapple go评论73阅读模式
英文:

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

&lt;div class=&quot;posts-section&quot;&gt;
&lt;div class=&quot;post-bar&quot;&gt;
&lt;div class=&quot;post_topbar&quot;&gt;
&lt;div class=&quot;usy-dt&quot;&gt;
&lt;img src={asset(&#39;small&#39;, item.users.profil_picture)} alt=&quot;&quot; /&gt;
&lt;div class=&quot;usy-name&quot;&gt;
&lt;h3 key={index}&gt;{item.users.name}&lt;/h3&gt;
&lt;span&gt;
&lt;img src=&quot;images/clock.png&quot; alt=&quot;&quot; /&gt;
{time(item.created_at)}
{/* { time(item.created_at)} */}
{/* {timePassed} */}
&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;Form onSubmit={handleSubmit} type=&quot;submit&quot;&gt;
&lt;InputGroup className=&quot;mb-3 comment-sect&quot;&gt;
&lt;InputGroup.Text id=&quot;inputGroup-sizing-default&quot;&gt;
&lt;Image src={asset(&#39;small&#39;, currentUser.profil_picture)} rounded className=&quot;profil-comment&quot; /&gt;
&lt;/InputGroup.Text&gt;
&lt;Form.Control
as=&quot;textarea&quot;
rows={1}
onChange={handleTextareaChange}
aria-label=&quot;Default&quot;
aria-describedby=&quot;inputGroup-sizing-default&quot;
// className={textareaValue.trim() !== &#39;&#39; ? &#39;filled&#39; : &#39;&#39;}
/&gt;
&lt;div
className={`comment-send-container ${textareaValue.trim() !== &#39;&#39; ? &#39;active-icon&#39; : &#39;disable-icon&#39;}`}
onClick={handleSubmit}
value={textareaValue}
&gt;
&lt;FontAwesomeIcon icon={faPaperPlane} className=&quot;comment-send-icon&quot; /&gt;
&lt;/div&gt;
&lt;/InputGroup&gt;
&lt;/Form&gt;
const handleSubmit = e =&gt; {
e.preventDefault()
const payload = {
comment: textareaValue,
user: currentUser.id,
}
console.log(payload)
}

答案1

得分: 0

&lt;Form onSubmit={{(e) =&gt; handleSubmit(e,item)}} type=&quot;submit&quot;&gt;

这部分代码将在你的函数中获取到该项

  const handleSubmit=(e,item)=&gt;{
e.preventDefault();
const payload={
// jobId : item.id **添加你的键**
comment:textareaValue,
user:currentUser.id,
}
console.log(payload);
}
英文:
&lt;Form onSubmit={{(e) =&gt; handleSubmit(e,item)}} type=&quot;submit&quot;&gt;

This item you can get in your function

  const handleSubmit=(e,item)=&gt;{
e.preventDefault();
const payload={
// jobId : item.id **Add your key**
comment:textareaValue,
user:currentUser.id,
}
console.log(payload);
}
</details>

huangapple
  • 本文由 发表于 2023年5月18日 08:58:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277098.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定