我正在使用角度1.0.5开发Rails 3.2.11应用程序。
目前,用户将从下拉列表中选择一个循环,这将使用ng-resource从我的控制器返回一堆JSON。 这是方法
$scope.update = function(cycleId) {
Cycle.get({action: cycleId}, function(resource) {
$scope.selectedCycle = resource;
$scope.tasks = resource.tasks;
$scope.newTask = {cycle_id: resource.cycle.id};
});
};
以下是我的控制器返回的json的示例,它是上述函数中的“资源”:https://gist.github.com/anonymous/01ffe5a37e370661f6fb
基本上我需要使用angulars ng-repeat两次使用ng-repeat(其中一个嵌套),这样我就可以在那里获得task_type_name作为标题。我得到了一些奇怪的有趣结果。请参阅下面我的视图中的简短代码和完整的here
<section ng-repeat="(task_type_name,task_type) in tasks ">
<h2>{{task_type_name}}</h2>
<table>
<tr>
<th>Task Name</th>
</tr>
<section id="task-edit">
<tr ng-repeat="task in task_type">
<td>
<%= link_to "{{task.name}}", '', "ng-click"=>"toggleShowHistory(task.id)" %>
</td>
</tr>
</section
</table>
所以我在这里发生了
<section id="task-edit">
<tr ng-repeat="task in task_type">
如果我尝试将该部分与tr组合,或者将tr更改为ANYTHING但是tr,{{task}}不再可用。
<section class="task-edit" ng-repeat="task in task_type">
{{task}} is available right here
<tr>
{{task}} is not available right here
<td>
{{task}} is not avaiable right here
</td>
</tr>
</section>
我在第一个循环上测试了相同的概念,它似乎在该循环上没有第二个嵌套循环。
我认为它与范围有关。但我只是没有得到它。 此外,如果你有任何提示,我对角度很新,并会喜欢它们。
答案 0 :(得分:2)