简体   繁体   English

当我们单击表中的每一行时如何重定向到不同的URL,即单击每一行元素必须重定向到不同的URL?

[英]How to redirect to different URLs when we click on each row in the table i.e, click on each row element must redirect to different URLs?

How to redirect to different URLs when we click on each row in the table ie, click on each row element must redirect to different URLs? 当我们单击表中的每一行时如何重定向到不同的URL,即单击每一行元素必须重定向到不同的URL?

I am working on Mustache Spring MVC framework where the entire data from MOngodb is retrieved onto a placeholder in the view page.So, now I need to be make this data click enable and each data row when clicked need to redirect to different URLs 我正在使用Mustache Spring MVC框架,在该框架中,将MOngodb中的所有数据检索到视图页面中的占位符上。因此,现在需要启用此数据单击,单击时每个数据行都需要重定向到不同的URL。

This is my table 这是我的桌子

<table>
  <tr>
    <th>Book Name</th>
    <th>Description</th>
  </tr>
  {{#books}}
  <tr>

    <td>{{book_name}}</td>

    <td>{{book_details}}</td>

  </tr>
  {{/books}}
</table>

Output looks like list of books and its description 输出看起来像书的清单及其说明

Now when I click on book1 it should go to some other URL and when I click on book2 it must go to another URL and so on 现在,当我单击book1时,它应该转到其他URL,而当我单击book2时,它必须转到另一个URL,依此类推

This must be a quick solution 这必须是一个快速的解决方案

 <table> <tr> <th>Book Name</th> <th>Description</th> </tr> {{#books}} <tr> <td onclick="window.location='{{book_url}}';>{{book_name}}</a></td> <td>{{book_details}}</td> </tr> {{/books}} </table> 

You can try something like this. 您可以尝试这样。 Here each url will be like some_url/book_name . 在这里,每个网址都将类似于some_url/book_name

<tr>
   <td>
      <a href="./some_url{{book_name}}">{{book_name}}</a>
   </td>
   <td>{{book_details}}</td>
</tr>

if I understood your problem correctly this will solve your problem 如果我正确理解了您的问题,这将解决您的问题

Add a field bool_url ( say bookUrl java specific ) to your Book bean. 在您的Book bean中添加一个bool_url字段(比如说bookUrl java specific)。 While adding book to database you need to specify that book_url too. 在将book添加到数据库时,您还需要指定该book_url

then following will work for you 那么以下将为您工作

<table>
    <tr>
        <th>Book Name</th>
        <th>Description</th>
    </tr>
    {{#books}}
        <tr>
            <td><a href="{{book_url}}">{{book_name}}</a></td>
            <td>{{book_details}}</td>
        </tr>
    {{/books}}
</table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM