0
Ich möchte Bootstrap Treeview Plugin in CodeIgniter konvertieren, läuft es normalerweise auf Core PHP, aber wenn ich es in CodeIgniter umwandeln, zeigt es nur Array-Ergebnis.Bootstrap Tree View Plugin konvertieren in codigniter?
Ergebnis: My code output
Quelle: Bootstrap Treeview source ich es in CodeIgniter
fetch.php
konvertieren möchten - Controller
<?php
class Fetch extends MY_Controller {
public function index() {
$this->load->view('dashboard');
// $query (= " SELECT * FROM country_state_city ";
$query = $this->db->query("SELECT * FROM country_state_city ");
// (" SELECT * FROM country_state_city ")->result_array() ;
//$output = array();
foreach ($query->result_array() as $row) {
$sub_data["id"] = $row["id"];
$sub_data["name"] = $row["name"];
$sub_data["text"] = $row["name"];
$sub_data["parent_id"] = $row["parent_id"];
$data[] = $sub_data;
}
foreach ($data as $key => &$value) {
$output[$value["id"]] = &$value;
}
foreach ($data as $key => &$value) {
if ($value["parent_id"] && isset($output[$value["parent_id"]])) {
$output[$value["parent_id"]]["nodes"][] = &$value;
}
}
foreach ($data as $key => &$value) {
if ($value["parent_id"] && isset($output[$value["parent_id"]])) {
unset($data[$key]);
}
}
echo json_encode($data);
}
}
?>
dashboard.php - Ansicht
<!DOCTYPE html>
<html>
<head>
<title>ajax jaquey tree grid</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
<script type="text/javascript" charset="utf8"
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootstrap-treeview.min.css"/>
<style>
</style>
</head>
<body>
<br/><br/>
<div class="container" style="width:500px;">
<h2 align="center">Make Treeview using Bootstrap Treeview Ajax JQuery with PHP</h2>
<br/><br/>
<div id="treeview"></div>
</div>
</body>
</html>
<script>
$(document).ready(function() {
$.ajax({
url: "<?php echo base_url();?>fetch",
method: "POST",
dataType: "json",
success: function (data) {
$('#treeview').treeview({data: data});
}
});
});
</script>
warum fügen Sie ''