layui之 子页面关闭刷新父页面(亲身测试,很实用)

版权声明:如有雷同,纯属巧合!!! https://blog.csdn.net/COCOLI_BK/article/details/87904116

layui - 子页面刷新父页面页面

 

 parent.layui.table.reload('educationReload',{page:{curr:1}});




子页面主要代码块

/* 表单提交 */
      form.on('submit(component-form-element)', function (data) {
        $.ajax({
          url: "/personnel/education",
          type: "put",
          contentType: "application/json", //设置请求参数类型为json字符串
          dataType: "json",
          data: JSON.stringify(data.field),
          success: function (res) {
              var index = parent.layer.getFrameIndex(window.name); /* 先得到当前iframe层的索引 */
              if (res.status == 200) {
                  parent.layui.table.reload('educationReload',{page:{curr:1}}); //主页代码,第一个参数为: 父页面的表格属性 id名
                  parent.layer.close(index); //成功再执行关闭
                  parent.layer.msg("编辑成功", {
                      icon: 6
                  });
              } else {
                  parent.layer.msg(res.msg, {
                      icon: 5
                  });
              }
          },
          error: function (res) {
            parent.layer.msg(res.msg, {
              icon: 5
            });
          }
        });
        return false;
      });
  • 父页面的主要代码:
  var contractTable = table.render({
        elem: '#staffContract' /* 所操作的表格id名 */,
        height: 'full-100' /* 表格有宽度之后,可设表格的高度最大化当前窗口 */,
        url: '/personnel/contract' /* 数据接口,渲染的接口路径 */,
        page: {
          layout: ['limit', 'count', 'prev', 'page', 'next', 'skip','refresh'] //自定义分页布局
          //,curr: 5 //设定初始在第 5 页
          ,groups: 4 //只显示 1 个连续页码
          ,first: true
          ,last: true

        },
        limit : 20,
        limits : [30,40,50],
        toolbar: '#operation',
        cellMinWidth:80,
        id: 'contractReload',   //关键点, 子页面的第一个参数
        cols: [
          [ /* 表头 */ {
            type: 'radio'
          }, {
            field: 'userNumber',
            title: '编号',
            align: 'center'
          }, {
            field: 'userName',
            title: '姓名',
            color: 'red',
            sort: true,
            align: 'center'
          }, {
            field: 'contractType',
            title: '合同类型',
            align: 'center'
          }, {
            field: 'contractTerm',
            title: '合同期限',
            sort: true,
            align: 'center'
          }, {
            field: 'contractStartDate',
            title: '合同起始日',
            align: 'center',
            sort: true,
            templet: function (res) {
              return _util(res.contractStartDate)
            }
          }, {
            field: 'contractEndDate',
            title: '合同结束日',
            sort: true,
            align: 'center',
            templet: function (res) {
              return _util(res.contractEndDate)
            }
          }, {
            field: 'probation',
            title: '试用期(月)',
            align: 'center'
          }, {
            field: 'contractRemarks',
            title: '备注',
            align: 'center',
            sort: true
          }]
        ],
        done: function (res, curr, count) { }
      });

猜你喜欢

转载自blog.csdn.net/COCOLI_BK/article/details/87904116
今日推荐