데이터 트리를 조작하고 있습니다. 주어진 노드에서, RESTful 서버에서 리턴 된 하위 노드를 추가해야 할 수도 있습니다. 요청 된 노드의 완전한 교체되는 ... ... 반환각도로 자식 노드 바꾸기
[{ "text":"Apples", "id":1, "childNodes":[
{ "text":"first Apple", "id":'1a', "childNodes":[] },
{ "text":"second Apple", "id":'1b', "childNodes":[] },
{ "text":"third Apple", "id":'1c', "childNodes":[] }
]
}]
을 : 데이터
[{ "text":"Apples", "id":1, "childNodes":[] },
{ "text":"Boxes", "id":2, "childNodes":[] },
{ "text":"Cups", "id":3, "childNodes":[] }]
다음 나는 "한 ID가"의 게시물을 ... 이런 식으로 뭔가를 찾고 밖으로 시작합니다. Angular는 모델을 올바르게 레이아웃하고, 데이터 변경을 수락하고, 변경 사항을 서버에 게시하고, 마지막 JSON BLOB를 수락합니다. 굉장해. 그러나 새 데이터로 $ 범위를 업데이트하는 방법을 모르겠습니다. 내보기 ...
<div ng-repeat="node in data.nodes" >
<p>{{node.text}}</p>
<button ng-click="addLoopInstance(node)">Add child nodes</button>
</div>
및 컨트롤러 ...
function SurveyController($scope, sampleService) {
$scope.addLoopInstance = function(node) {
sampleService.post({ id: node.id }, function(response, getResponseHeaders) {
// this doesn't work
node = response;
// neither does this
$scope.$apply(function() {
node = response;
});
});
}
}
어떤 생각을 다음과 같이 보입니다? 미리 감사드립니다. Angular 문서는 ... 원합니다 ...하지만 사용자 기반이 매우 유용하다는 것을 알았습니다.
'node.childNodes = response.childNodes'를 대신 사용 하시겠습니까? –