0
我有任務列表中可能有子任務等。這是嵌套結構,我不想加載整個樹,我只想加載根級別,然後按用戶需求加載每個分支。所以我使用嵌套ng-includes
和ng-init
通過TAKS的列表,這裏是模板:綁定中斷與嵌套ngInclude
<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創建新的子範圍。我如何處理這個問題?
這裏是花掉這個http://plnkr.co/edit/AkIZV1PkD5a3AzCBen8R
這裏是我測試你的猜測http://plnkr.co/edit/jUSli6m1uz63BJj7Rom3但這沒有幫助。我認爲'task.subtasks'未定義的事實不是問題,$ scope.tasks在某些時候也是未定義的,但這不會導致問題... – SET
如果您查看生成的html,正在生成孩子,但它們是隱藏的。 – Chandermani
確實,對不起,我的錯。 Thanx,它確實有效 – SET