मैं कोडिनेटर और mysql का उपयोग करके गतिशील वृक्ष मेनू बनाना चाहता हूं, मुझे पेड़ संरचना के लिए सीएसएस & jquery के साथ कोई समस्या नहीं है।कोडनिर्देशक और mysql गतिशील रूप से वृक्ष संरचना कैसे बनाएं
function getOrganization(){
$this->db->select('organization.*, organization.id as id, parent.id as parent_id, parent.title as organization_parent, organization_class.title as organization_class, organization.title as title');
$this->db->from('organization');
$this->db->join('organization_class', 'organization.organization_class_id = organization_class.id', 'left');
$this->db->join('organization as parent', 'organization.parent_organization_id = parent.id', 'left');
$this->db->order_by('organization.organization_class_id', 'asc');
$query = $this->db->get();
return $query;
}
मैं सिर्फ कर सकते हैं:
$str ='';
$lastListLevel=0;
$firstRow=true;
foreach($organization->result() as $row){
$currentListLevel=$row->parent_organization_id -1 ; // minus one to correct level to Level 0
$differenceLevel=$currentListLevel-$lastListLevel;
$rootLevel=false;
if($differenceLevel==0){
if($firstRow){
$firstRow=false;
}else{
$str .='</li>';
}
$str .='<li>';
}elseif($differenceLevel>0){
for($j=0;$j<$differenceLevel;$j++){
$str .='<ul><li>';
}
}elseif($differenceLevel<0){
for($j=$differenceLevel;$j<=0;$j++){
if($j==0){ // root level reached
$rootLevel=true;
$str .='</li>';
}else{
$str .='</li></ul>';
}
}
$str .= ($rootLevel) ? '<li>' : '<ul>';
}
$str.='<span><i class="icon-minus-sign"></i>'.$row->parent_organization_id.'-'.$row->organization_class_id.'-'.$row->id.'--'.$row->title.'--'.$row->organization_class.'</span>'.'<button type="button" class="btn btn-info btn-small" data-toggle="modal" data-target="#editorganizationModal'.$row->id.'"><i class="icon-paste"></i></button>';?>
<?php
$lastListLevel=$currentListLevel;
}echo $str.'<br>Lowest organization level. Please define new lower level to add.<br />';?>
यह मेरा मॉडल है:
(id, parent_org_id, org_class_id, title)
(1, 0, 1, Company Name)
(2, 0, 1, Company2 Name)
(3, 1, 2, Departement Name)
(4, 2, 2, Departement2 Name)
(5, 4, 3, Division2 Name)
(id, org_class_title, order_no)
(1, 0, 1)
(2, 0, 2)
(3, 1, 3)
यह मेरा समारोह है:
मैं दो टेबल, मेज संगठन & संगठन वर्ग है organization_parent
के लिए पेड़, और परिणाम इस तरह है:
-- Company Name - Company
-- Company Name 2 - Company
--Departement Name - Departement
--Departement2 Name - Departement
--Division Name2 - Division
और मैं इस तरह परिणाम बनाना चाहते:
-- Company Name - Company
--Departement Name - Departement
-- Company Name2 - Company
--Departement2 Name - Departement
--Division2 Name - Division
या परिणाम इस तरह हो सकता है अगर HTML में:
<ul>
<li>Company Name - Company
<ul>
<li>Departement Name - Departement</li>
</ul>
</li>
<li>Company Name2 - Company
<ul>
<li>Departement Name2 - Departement
<ul>
<li>Divison Name2 - Division</li>
</ul>
</li>
</ul>
</li>
</ul>
क्या आप डेटा को अपने वृक्ष संरचना से पहले एक सरणी संरचना में डाल रहे हैं? – Edward
मुझे अपना मॉडल जोड़ा गया है, –
इस तरह के कार्यों में, एक सामान्य संकेत के रूप में, आपको एक फ़ंक्शन को परिभाषित करना होगा जो पेड़ नोड बनाता है और यह कार्य, सशर्त रूप से, बच्चों को नोड जोड़ने के लिए स्वयं को कॉल करता है। i.e 'फ़ंक्शन dTree() {// कोड; अगर (हालत) {dTree();}}' शर्त यह जांचने वाली है कि नोड का बच्चा है या नहीं। – SaidbakR