怎样通过点击列表的每一行跳转至新页面(详情页)

在网站或OA系统中,我们经常需要通过页面列表点击某行查看详细信息:

1.js代码:

 1 $(function(){
 2     $.each($("#listtable tr:gt(1)"),function(index,o){    //gt()下标从0开始,表示从大于1的行开始
 3         var outId = $(o).attr("id"); 
 4         $(o).click(function(){
 5             var bodyWidth = window.screen.width-100;
 6             var bodyHeight = window.screen.height-150;
 7             var url = document.getElementById("url").value;
 8             var style = "status=no,maximize=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,top=15,left=50, resizable=yes,height="+bo
dyHeight+",width="+bodyWidth; 9 window.open('yzArchivesOut.action?oper=showDetail&outId='+outId+"&url="+url,'newwindow',style); 10 }); 11 }); 12 });

2.jsp代码:

<body>
    <table id="listtable" >
        <tr></tr>
        <tr>
             <td></td>
             <td></td>
             <td></td>
             <td></td>
        </tr>
        <c:forEach items="" var="" varStatus="">
             <tr id="">
                 <td></td>
                 <td></td>
                 <td></td>
                 <td></td>
             </tr>
        </c:forEach>
    </table>
 </body>

 

转载于:https://www.cnblogs.com/lxcmyf/p/5460955.html

在Element UI中,为了实现表格(el-table)单击某一行数据时跳转详情页面并传递该行的数据,通常需要结合Vue.js的事件监听机制以及路由管理。以下是一个基本步骤的示例: 1. 安装和引入依赖: 确保已经安装了vue-router和axios(如果用于API请求),可以在main.js中引入它们: ```javascript import VueRouter from 'vue-router'; import axios from 'axios'; Vue.use(VueRouter); ``` 2. 定义路由: 创建一个新的路由,比如`/detail/:id`,`id`是动态参数,用于接收表单的行ID: ```javascript const router = new VueRouter({ routes: [ { path: '/detail/:id', component: DetailComponent }, ], }); ``` 3. 表格组件模板: 在`el-table`组件中,给每一行设置一个`click`事件处理器,传递当前行的数据: ```html <el-table :data="tableData" @row-click="handleRowClick"> <!-- ...其他列 --> <template slot-scope="scope"> <el-button type="primary" @click="jumpToDetail(scope.row)">查看详情</el-button> </template> </el-table> ``` 4. JavaScript处理函数: ```javascript data() { return { tableData: [], }; }, methods: { handleRowClick(row) { this.$router.push(`/detail/${row.id}`); }, async jumpToDetail(row) { try { // 如果有额外的数据获取需求,可以发送axios请求 await this.fetchDetails(row.id); // 跳转前不做任何操作或只做一些简单的处理 } catch (error) { console.error('Error fetching details:', error); } }, fetchDetails(id) { axios.get('/api/details/' + id) .then(response => { // 更新详情数据,如果需要显示在详情页 this.detailData = response.data; }) .catch(error => console.error('Failed to fetch details:', error)); }, }, created() { // 初始化数据 this.fetchTableData(); }, // ...其他生命周期钩子 ``` 5. 以上代码中,`fetchTableData()`用于从服务器获取初始数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值