Jeesite框架实用 前端页面如何实现双表联动


前言

有时我们需要两张相关联的表,显示在一个页面上,并且具备一些功能。如图:

由图可知,上下两张表是单独的,只有创会id是相同的

上表,可以翻页,并且选中后双击,便可以在下表的审查中,显示id相同的信息。


一、问题

如何制作这张双表联动?

二、使用步骤

1.模板

可以直接复制模板到HTML中,然后在进行修改即可。关键要修改的地方,已标注一二三。

代码如下(示例 由jeesite框架源码中demo提供):

<% layout('/layouts/default.html', {title: '多表格联动示例', libs: ['layout', 'dataGrid']}){ %>
<div class="ui-layout-north">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                
                // 1. 此处的('岗位列表')}(多表格联动示例) 可以修改 ,是上表的标题
                
                    <i class="fa icon-trophy"></i> ${text('岗位列表')}(多表格联动示例)
                </div>
            </div>
            <div class="ui-layout-content">
            
            // 2.这个是上表数据来源和显示多少数据的地方
            
                <#form:form id="searchForm" model="${post!}" action="${ctx}/sys/post/listData" method="post" class="form-inline hide"
                data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize!3}"
                data-order-by="${parameter.orderBy!'post_code desc'}">
                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
                    <button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
                </div>
            </#form:form>
            <table id="dataGrid"></table>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
</div>
<div class="ui-layout-center">
    <div class="main-content">
        <div class="box box-main">
            <div class="box-header">
                <div class="box-title">
                
                // 3. 此处的(('用户列表')}(点击岗位查询对应用户) 可以修改 ,是下表的标题
                
                    <i class="fa icon-user"></i> ${text('用户列表')}(点击岗位查询对应用户)
                </div>
            </div>
            <div class="ui-layout-content">
            
            // 4.这个是下表数据来源和显示多少数据的地方
            
                <#form:form id="searchForm2" model="${empUser!}" action="${ctx}/sys/empUser/listData" method="post" class="form-inline hide"
                data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize!6}"
                data-order-by="${parameter.orderBy}">
                <div class="form-group">
                    <label class="control-label">${text('岗位')}:</label>
                    <div class="control-inline width-90">
                    
                    //5.这是上表的id值 ,是为了上表双击,下表显示相同id信息。
                    
                        <#form:input name="employee.postCode" id="postCode" class="form-control"/>
                    </div>
                </div>
            </#form:form>
            <table id="dataGrid2"></table>
            <div id="dataGrid2Page"></div>
        </div>
    </div>
</div>
</div>

<% } %>
<script>
    // 初始化布局
    $('body').layout({
        north__size: 300,
        onresize: function(){
            $(window).resize();
        }
    });
    // 初始化DataGrid对象
    $('#dataGrid').dataGrid({
        searchForm: $("#searchForm"),
        dataGridPage: $('#dataGridPage'),
        autoGridHeight: function(){
            return $('#searchForm').parent().height() - $('#dataGridPage').height() - 45;
        },
        columnModel: [
        
        //6.上表显示的信息
        
            {header:'${text("岗位名称")}', name:'postName', index:'a.post_name', width:200, align:"center"},
            {header:'${text("岗位编码")}', name:'postCode', index:'a.post_code', width:200, align:"center"},
            {header:'${text("排序号")}', name:'postSort', index:'a.post_sort', width:80, align:"center"},
            {header:'${text("岗位分类")}', name:'postType', index:'a.post_type', width:100, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('sys_post_type')}, val, '未知', true);
                }},
            {header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:150, align:"center"},
            {header:'${text("备注信息")}', name:'remarks', index:'a.remarks', width:200, align:"left"},
            {header:'${text("状态")}', name:'status', index:'a.status', width:80, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('sys_status')}, val, '未知', true);
                }}
        ],
        onSelectRow: function(id, isSelect, event){
            $('#postCode').val(id);
            $('#dataGrid2').dataGrid('refresh');
        },
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });
    // 初始化DataGrid对象
    $('#dataGrid2').dataGrid({
        searchForm: $("#searchForm2"),
        dataGridPage: $('#dataGrid2Page'),
        autoGridHeight: function(){
            return $('#searchForm2').parent().height() - $('#dataGrid2Page').height() - 45;
        },
        columnModel: [
        
        // 7.下表显示的信息
        
            {header:'${text("登录账号")}', name:'loginCode', index:'a.login_code', width:200, align:"center"},
            {header:'${text("用户昵称")}', name:'userName', index:'a.user_name', width:200, align:"center"},
            {header:'${text("员工姓名")}', name:'refName', index:'a.ref_name', width:200, align:"center"},
            {header:'${text("归属机构")}', name:'employee.office.officeName', index:'o.office_name', width:200, align:"center"},
            {header:'${text("归属公司")}', name:'employee.company.companyName', index:'c.company_name', width:200, align:"center"},
            {header:'${text("电子邮箱")}', name:'email', index:'a.email', width:200, align:"center"},
            {header:'${text("手机号码")}', name:'mobile', index:'a.mobile', width:200, align:"center"},
            {header:'${text("办公电话")}', name:'phone', index:'a.phone', width:200, align:"center"},
            {header:'${text("更新时间")}', name:'updateDate', index:'a.update_date', width:200, align:"center"},
            {header:'${text("状态")}', name:'status', index:'a.status', width:140, align:"center", formatter: function(val, obj, row, act){
                    return js.getDictLabel(${@DictUtils.getDictListJson('sys_status')}, val, '未知', true);
                }}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function(data){

        }
    });
</script>

2.修改数据

上表和下表这两个表联动 ,其实jeesite是可以生成两张单独的表,单独的list和form页面的

1. 模板中  第二步和第四步 可以直接从 上表单独的lits 和下表单独的list  中 <#form:form > 找到这个标签里的内容 复制粘贴过来就行。

data-page-size="${parameter.pageSize!3}   其中这个 !3  表示一次显示三行信息。

2. 模板中 第五步

<#form:input name="employee.postCode" id="postCode" class="form-control"/>

这个那么name  要注意  :如果是两张单表 只有id相关联   name 只需填id的名称就行比如 meetingId

                                          这里employee.postCode 是因为   employee是上下表中间的一张关联表,上下表的id不同,employee只存储两张表的id。

3. 模板中第六 第七步

也可以从上下表中单独的list中复制粘贴过来。


总结

修改数据 中的 2 一定要注意,这里name的值填写极易出现错误

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
在MongoDB中,可以使用聚合查询和嵌入式文档的方式来实现双表查询。在聚合查询中,可以使用$lookup操作符来进行多表关联查询。$lookup操作符可以在一个集合中查找匹配条件的记录,并将其与另一个集合中的记录关联起来。 首先,你需要使用$lookup操作符指定要关联的集合和关联条件。例如,如果你有两个集合A和B,你可以使用以下代码进行关联查询: ``` db.A.aggregate([ { $lookup: { from: "B", localField: "fieldA", foreignField: "fieldB", as: "result" } } ]) ``` 这个查询将在集合A中的fieldA字段和集合B中的fieldB字段之间进行匹配,并将匹配的记录作为嵌入式文档添加到A的每个记录中的result字段中。 另一种实现双表查询的方式是使用嵌入式文档。在MongoDB中,你可以在一个集合中嵌入另一个集合的记录。例如,如果你有两个集合A和B,你可以将B的记录嵌入到A的记录中。这样,当你查询A集合时,可以同时获取A和B的数据。 这里是一个示例代码: ``` db.A.find().forEach(function(doc) { var b = db.B.findOne({ _id: doc.bId }); doc.b = b; printjson(doc); }); ``` 这段代码将遍历A集合中的每个记录,并使用B集合中与之相关联的记录更新每个A记录中的b字段。 总结起来,MongoDB可以使用聚合查询和嵌入式文档的方式实现双表查询。聚合查询使用$lookup操作符进行关联查询,而嵌入式文档则将一个集合的记录嵌入到另一个集合的记录中。根据具体的需求和数据结构,你可以选择适合的方式来实现双表查询。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [java mongodb 多表关联查询,多条件查询,分页,排序](https://blog.csdn.net/seesun2012/article/details/105165495)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [MongoDB 多表连接查询](https://blog.csdn.net/weixin_39653761/article/details/113432062)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喂马人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值