繁体   English   中英

使用模式显示来自另一个表的数据-Codeigniter

[英]Show data from another table with modal - Codeigniter

我有2张桌子

表1(图1)

现在,当我单击详细信息时,我想显示表2中的数据,因为我单击表1时具有报告代码(图像1)

表2(图2)

现在我想在模式上显示它,所以这是示例

1)单击详细信息按钮->获取报告代码->显示报销名称等为模态

你能告诉我我应该先做什么吗? 并能给我建议一个计划,任何答案将不胜感激。 谢谢

我的建议是:

1-向详细信息按钮添加一个类,即: detailButton和具有especific reportCode的数据属性或href。

<table>
   <tr> 
     <td> ... </td>
     <td> <button class='detailButton' href='<?php echo $reportCode; ?>' ... </button> </td>

2-将jquery添加到页面底部:

$('.detailButton').click(function(e){
    e.preventDefault();
    var reportCode = $(this).attr('href');

    var url = "yourUrl/controller/function";
    $.post(url,{ code:reportCode },function(data){
        //do stuff
        //i.e: $('.modal').html(data).show();
    });
});

现在,您有了一个获取reportCode的函数,并通过POST将其发送到控制器,您返回了一些内容,并且该函数获取了响应并附加到html。

注意,这种方式必须从控制器返回一个表。 您也可以进行动态构建。

希望能帮助到你!

更新:您可以检查模型中的值,然后使用一个exisitin模板(例如,一个生成明细表的模板),并作为要附加到正确位置的数据返回到视图(方法1):

function detail(){
    $getcode= $this->input->post('reportCode');
    $data['showdetail'] = $this->model_expreport->showdetail($getcode);
    $ret = $this->load->view('detail_template',$data,true); //return as data   
    print_r($ret);
}

或者,您可以使用方法2:

function detail(){    
   $getcode= $this->input->post('reportCode');
   $data['showdetail'] = $this->model_expreport->showdetail($getcode);

   $this->output->set_content_type('application/json');
   $this->output->set_output(json_encode($data));
}

这样,视图将获取可迭代并构建自己的页面的JSON。 或者,您可以创建完整视图并将其作为数据返回(以便仅附加到视图中)。

您可以同时使用。

在视图中,您将获得完整视图:

$.post(url,{ code:reportCode },function(data){
    $('#modal').html(data); //put the 'detail' response to the modal
}

或使用JSON,您必须进行迭代并动态创建自己的div,为此有很多教程: https : //uno-de-piera.com/cargar-json-con-jquery-y-codeigniter/

暂无
暂无

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

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