欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

在Layui 的表格模板中,實(shí)現(xiàn)layer父頁(yè)面和子頁(yè)面?zhèn)髦到换サ姆椒?/h1>
 更新時(shí)間:2019年09月10日 10:07:48   作者:CoderBruis  
今天小編就為大家分享一篇在Layui 的表格模板中,實(shí)現(xiàn)layer父頁(yè)面和子頁(yè)面?zhèn)髦到换サ姆椒?,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

最近,在項(xiàng)目中使用到了layer。layer的彈層組件可以說(shuō)是非常好用,layer 至今仍作為 layui 的代表作。在項(xiàng)目中,需要實(shí)現(xiàn)一個(gè)在表格里面點(diǎn)擊操作,然后彈出layer層,將父層表格的行值傳給子頁(yè)面,子頁(yè)面拿到值后,進(jìn)行業(yè)務(wù)處理,從而實(shí)現(xiàn)真正的父子頁(yè)面交互。

其實(shí),官方文檔都說(shuō)的很清楚了。

layui官方文檔:http://layer.layui.com/

使用版本:2.3.0

只是,需要我們耐心的讀懂文檔內(nèi)容,然后根據(jù)自己的業(yè)務(wù)情況,實(shí)現(xiàn)自己想要的效果。

一、子頁(yè)面獲取父頁(yè)面數(shù)據(jù)

子頁(yè)面,要獲取父頁(yè)面的內(nèi)容,需要使用到layui的一個(gè)關(guān)鍵字:parent。通過(guò)parent,子頁(yè)面就可以獲取到父頁(yè)面上的數(shù)據(jù)了。

例子:從父頁(yè)面的表格中,點(diǎn)擊行的操作按鈕,彈出layer層,并將該行的數(shù)據(jù)傳給layer層。

<table id="role_tb" class="layui-table" lay-data="{width: 1007, height:365, url:'http://localhost:8080/rolelist', page:false, id:'idTest'}" lay-filter="demo">
  <thead>
  <tr>
  <th lay-data="{field:'id', width:100, sort: true}">角色I(xiàn)D</th>
  <th lay-data="{field:'name', width:140}">角色名稱(chēng)</th>
  <th lay-data="{field:'description', width:250}">角色描述</th>
  <th lay-data="{field:'str_createdate', width:200, sort: true}">創(chuàng)建時(shí)間</th>
  <th lay-data="{field:'str_updatedate', width:200, sort: true}">更新時(shí)間</th>
  <th lay-data="{fixed: 'right', width:110, align:'center', toolbar: '#barDemo'}">操作</th>
  </tr>
  </thead>
 </table>

該表格是由layui根據(jù)后臺(tái)接口動(dòng)態(tài)渲染出來(lái)的,那么該如何獲取點(diǎn)擊按鈕所處該行的數(shù)據(jù)呢?

下列方法完美解決了這個(gè)問(wèn)題!

//這里設(shè)置一個(gè)空的json串,用于接受表格的行信息
var json;
 
layui.use('table', function(){
  var table = layui.table;
  //監(jiān)聽(tīng)工具條
  table.on('tool(demo)', function(obj){
   var data = obj.data;
    if(obj.event === 'find'){
    //這行是監(jiān)聽(tīng)到的表格行數(shù)據(jù)信息,復(fù)制給json全局變量。 
    json = JSON.stringify(data);
    layui.use('layer', function () {
    layer.open({
    title: '查看權(quán)限',
    maxmin: true,
    type: 2,
    content: './privileages-manage.html',
    area: ['800px', '500px']
   });
   });
  }
  });
});
 

----------------------------------------------------這里是子層代碼:

$(function () {
  //從父層獲取值,json是父層的全局js變量。eval是將該string類(lèi)型的json串變?yōu)闃?biāo)準(zhǔn)的json串
  var parent_json = eval('('+parent.json+')');
  console.log(parent_json);  
});

看一下父層和子層的效果。

這樣,子頁(yè)面就從父頁(yè)面獲取到了數(shù)據(jù)。接下來(lái)就根據(jù)自己的業(yè)務(wù),處理數(shù)據(jù)吧。

所以,可以通過(guò)parent關(guān)鍵字,子頁(yè)面就可以調(diào)用父頁(yè)面的變量、方法。還可以刷新父頁(yè)面。

parent.location.reload(); // 父頁(yè)面刷新

二、父頁(yè)面獲取子頁(yè)面數(shù)據(jù)

進(jìn)入layer官方文檔,認(rèn)真閱讀,并且可以操作下面的代碼,效果更佳直觀。http://layer.layui.com/

//注意:parent 是 JS 自帶的全局對(duì)象,可用于操作父頁(yè)面
var index = parent.layer.getFrameIndex(window.name); //獲取窗口索引
 
//讓層自適應(yīng)iframe
$('#add').on('click', function(){
 $('body').append('插入很多醬油。插入很多醬油。插入很多醬油。插入很多醬油。插入很多醬油。插入很多醬油。插入很多醬油。');
 parent.layer.iframeAuto(index);
});
//在父層彈出一個(gè)層
$('#new').on('click', function(){
 parent.layer.msg('Hi, man', {shade: 0.3})
});
//給父頁(yè)面?zhèn)髦?
$('#transmit').on('click', function(){
 parent.$('#parentIframe').text('我被改變了');
 parent.layer.tips('Look here', '#parentIframe', {time: 5000});
 parent.layer.close(index);
});
//關(guān)閉iframe
$('#closeIframe').click(function(){
 var val = $('#name').val();
 if(val === ''){
  parent.layer.msg('請(qǐng)?zhí)顚?xiě)標(biāo)記');
  return;
 }
 parent.layer.msg('您將標(biāo)記 [ ' +val + ' ] 成功傳送給了父窗口');
 parent.layer.close(index);
});
 

以上這篇在Layui 的表格模板中,實(shí)現(xiàn)layer父頁(yè)面和子頁(yè)面?zhèn)髦到换サ姆椒ň褪切【幏窒斫o大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論