【问题标题】:How to send a value through the btn for the route如何通过 btn 为路由发送值
【发布时间】:2020-10-31 15:28:33
【问题描述】:

您好,我是初学者,我想知道如何在单击 btn 时将事件的 Id 发送到“/checkin”路由。

代码如下:

        {{#each events}}
        <tr>
          <td>{{this.subject}}<br><a href="/checkin" class="btn btn-primary btn-large">Click here to checkin</a>
    </td>
          <td>{{this.location.displayName}}</td>
          <td>{{eventDateTime this.start.dateTime}}</td>
          <td>{{eventDateTime this.end.dateTime}}</td>
        </tr>
      {{/each}}
    </tbody>

【问题讨论】:

    标签: javascript html node.js reactjs


    【解决方案1】:

    你可以通过路线做到这一点!像这样:

    href={"/checkin?EventId=" + event.id }
    

    href={`/checkin?EventId=${event.id}`}
    

    而当 /checkin 加载时,只需使用这行代码来获取值:

    new URLSearchParams(window.location.search).get('EventId')
    

    希望对你有帮助!

    【讨论】:

    • 返回此错误“ReferenceError: window is not defined”
    【解决方案2】:

    如果您想将事件 ID 作为查询参数传递,您可以像这样将其连接到路由:

          {{#each events}}
            <tr>
              <td>{{this.subject}}<br><a href={`/checkin?id=${this.id}`} class="btn btn-primary btn-large">Click here to checkin</a>
        </td>
              <td>{{this.location.displayName}}</td>
              <td>{{eventDateTime this.start.dateTime}}</td>
              <td>{{eventDateTime this.end.dateTime}}</td>
            </tr>
          {{/each}}
    

    【讨论】:

      猜你喜欢
      • 2018-11-24
      • 1970-01-01
      • 1970-01-01
      • 2019-10-28
      • 2017-12-05
      • 2018-02-13
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      相关资源
      最近更新 更多