如何使用Codeigniter 3 HMVC在dhtmlx网格中加载json数据?

时间:2016-03-02 07:37:57

标签: json codeigniter dhtmlx

我从控制器中提取json数据,但我不知道如何在网格中渲染这些数据。

这是我的示例代码:

查看

<script type="text/javascript">

    var myGrid;

    function loadProjects() {
        myGrid = new dhtmlXGridObject('project-list');
        myGrid.setHeader("ID, Contract ID, Client ID, Client, Assigned Officer, Start Date, End Date, Status"); 
        myGrid.init();
        myGrid.load("<?php echo site_url('projects/projects/load_project_list'); ?>");
    }

    $(window).on('load', function() {
        loadProjects();
    });

</script>

CONTROLLER

public function load_project_list() {

    header('Access-Control-Allow-Origin: *');
    header("Content-Type: application/json");
    $json = array();
    $this->load->model('projects/Projects_model');
    $projects = $this->Projects_model->get_projects();
    $json['data'] = $projects;
    echo json_encode($json);;

}

模型

public function get_projects() {
        $list = $this->db->get('tr_projects');
        return ($list) ? $list->result() : array();
    }

示例JSON:

{"data":[{"id":"1","contract_id":"542454","client_id":"5641454","client":"Terada","officer":"Miki","start_date"
:"2016-03-02","end_date":"2016-03-02","status":"1"},{"id":"2","contract_id":"423434","client_id":"6534544"
,"client":"Meme","officer":"Miki","start_date":"2016-03-02","end_date":"2016-03-02","status":"1"}]
}

我可以获取json值但它没有显示在表中。我需要做一个JSON格式吗?

0 个答案:

没有答案