我如何做一个AJAX嵌套列表,在AngularJS? [英] How do I make a AJAX nested list, in AngularJS?
本文介绍了我如何做一个AJAX嵌套列表,在AngularJS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了一个列表谁的内容是通过AJAX加载,它可以作为预期。
I've made a list who's content is loaded via AJAX, and it works as intended.
我现在想使每个列表项的负载(通过AJAX),当点击时显示一个子表。
I'd now like to make each list entry load (via AJAX) and display a sublist, when clicked upon.
这是可能的AngularJS? (我是新来的AngularJs和我多带点迷糊超过$范围。)
Is this possible in AngularJS? (I'm new to AngularJs and am more than a little confused over $scope.)
<div ng-controller="StockGroupCtrl">
<ul>
<li ng-repeat="group in groups">
<span>{{group.prod_grp}}</span>
<span>{{group.desc}}</span>
<!-- something like
<ul ng-controller="WhatShouldItBe?">
<li ng-repeat="item in items">
<span>{{item.name}}</span>
<span>{{item.price}}</span>
</li>
</ul>
-->
</li>
</li>
</div>
我已经做外code的工作有:
I've made the outer code work with:
function StockGroupCtrl($scope, $http) {
$scope.groups = [];
$scope.handleGroupsLoaded = function(data, status) {
$scope.groups = data;
}
$scope.fetch = function() {
$http.get('/api/stock/groups/').success($scope.handleGroupsLoaded);
}
$scope.fetch();
}
但我实在看不出哪里开始与内部列表。
but I can't really see where to start with the inner lists.
推荐答案
这个怎么样?你并不需要另一个控制器。
How about this? You don't need another controller.
<ul>
<li ng-repeat="item in group.items">
<span>{{item.name}}</span>
<span>{{item.price}}</span>
</li>
</ul>
这篇关于我如何做一个AJAX嵌套列表,在AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文