我有可能有子任务等的任务列表。这是嵌套结构,我不想加载整个树,我只想加载根级别,然后根据用户需求加载每个分支。所以我使用嵌套ng-includes
并ng-init
传递任务列表,这是模板:
<div ng-repeat="task in tasks" class="task">
{{task.name}}
<a href ng-click="expand(task)">expand</a>
<a href ng-click="remove(task, tasks)">remove</a>
<div ng-show="task.subtasks" ng-init="tasks = task.subtasks" ng-include="'tasks.html'"></div>
</div>
控制器:
app.controller 'MainCtrl', ($scope, $http) ->
$http.get('tasks.json').then (tasks) ->
$scope.tasks = tasks.data
$scope.expand = (task) ->
if !task.subtasks
$http.get("subtasks.json").then (tasks) ->
task.subtasks = tasks.data
task.expanded = yes
$scope.remove = (task, list) ->
list = _.reject list, id:task.id
当用户展开分支和子任务被加载时,它不会在视图中更新,所以我假设 ng-include 创建新的子范围。我该如何处理这个问题?