आप AngularJS पर विस्तारित/संक्षिप्त उपमेनू बनाने के लिए निम्न कोड का उपयोग कर सकते हैं।
मैंने आपके लिए JSFiddle उदाहरण संलग्न किया है।
<div ng-controller="MyCtrl">
<ul>
<li ng-repeat="item in items" ng-click="showChilds(item)">
<span>{{item.name}}</span>
<ul>
<li ng-repeat="subItem in item.subItems" ng-show="item.active">
<span>---{{subItem.name}}</span>
</li>
</ul>
</li>
</ul>
</div>
आपका जे एस नियंत्रक:
function MyCtrl($scope) {
$scope.showChilds = function(item){
item.active = !item.active;
};
$scope.items = [
{
name: "Item1",
subItems: [
{name: "SubItem1"},
{name: "SubItem2"}
]
},
{
name: "Item2",
subItems: [
{name: "SubItem3"},
{name: "SubItem4"},
{name: "SubItem5"}
]
},
{
name: "Item3",
subItems: [
{name: "SubItem6"}
]
}
];
};
अद्यतन:
मैं के बारे में, जब हम नए मेनू के आइटम पर क्लिक करें, पिछले है कि अपनी टिप्पणी की वजह से मेरी पोस्ट को नवीनीकृत किया है ढह जाना चाहिए
कोड में छोटे बदलाव। आपकी आवश्यकता के साथ
नई JSFiddle।
<div ng-controller="MyCtrl">
<ul>
<li ng-repeat="item in items" ng-click="showChilds($index)">
<span>{{item.name}}</span>
<ul>
<li ng-repeat="subItem in item.subItems" ng-show="item.active">
<span>---{{subItem.name}}</span>
</li>
</ul>
</li>
</ul>
</div>
आप जे एस नियंत्रक:
function MyCtrl($scope) {
$scope.showChilds = function(index){
$scope.items[index].active = !$scope.items[index].active;
collapseAnother(index);
};
var collapseAnother = function(index){
for(var i=0; i<$scope.items.length; i++){
if(i!=index){
$scope.items[i].active = false;
}
}
};
$scope.items = [
// items array the same with the previous example
];
};
स्रोत
2014-10-26 09:04:16
हाय Artyom, मैं साइट मैं करने के लिए भेजा पर मेनू के रूप में कार्य उप मेनू के साथ मेरी menulist के लिए कोशिश कर रहा हूँ। जब आप एक मेनू लिंक पर क्लिक करते हैं तो इसके अंतर्गत की सूची विस्तारित होती है, यदि आप किसी नए तत्व पर क्लिक करते हैं तो पुराना सबमेनू बंद हो जाता है और नया सब-मेन्यू फैलता है। =) – Bent