지침

2014-04-08 2 views
0

나는 같은 보이는 개체가 있습니다지침

RecruitingGroups 
{ 
    GroupName = "stuff", 
    GroupTarge = 1, 
    Rule = 
    { 
    Id = 1, 
    Match = All, 
    Tags = 
    { 
     1, 
     2, 
    } 
    } 
} 

내 각도가 너무과 같다 :

app.directive('creategroup', function() { 
    return { 
     restrict: 'E', 
     templateUrl: '../../Content/templates/RecruitingGroups/CreateGroup.html', 
     link: function (scope, el) { 
      scope.groups = data.RecruitingGroups; 

      scope.createGroup = function() { 
       scope.groups.push({ id: scope.groups.length }); 
      } 
     } 
    } 
}); 

app.directive('group', function() { 
    return { 
     restrict: 'E', 
     scope: true, 
     templateUrl: '../../Content/templates/RecruitingGroups/Group.html', 
     link: function (scope, el) { 
      scope.rules = []; 
      scope.addRule = function() { 
       scope.rules.push({ id: scope.rules.length }); 
      } 
     } 
    } 
}); 

app.directive('rule', function() { 
    return { 
     restrict: 'E', 
     scope: true, 
     templateUrl: '../../Content/templates/RecruitingGroups/Rule.html', 
     link: function (scope, el) { 
      scope.tags = []; 
      scope.addTag = function() { 
       scope.tags.push({ id: scope.tags.length + 1 }); 
      } 
     } 
    } 
}); 

여기 단어에 대한 어려움을 겪고 있어요,하지만 어떻게해야 규칙 객체 (그룹 객체의 자식)를 지시문의 올바른 위치에 놓습니다. 예상 출력의 스크린 샷을 보여 주면 더 자세히 설명 할 수 있습니다. Groups

각 그림에는 각각 하나의 규칙으로 된 두 개의 그룹이 있습니다. 각 규칙에는 그 안에 태그가 있습니다. 그것이 내가 쏘고있는 결과입니다.

답변

1

규칙 및 그룹에 대한 범위 배열을 만들고 필요에 따라 ng-repeat를 사용하여 내 지시문 태그를 반복합니다.

기 각 개체 (그룹) 오브젝트의 배열 (규칙)을 추가 할 때

+0

내가 가진 유일한 문제가있는 속성 규칙이 오브젝트의 배열이

<group ng-repeat="group in groups"> <rule ng-repeat="rule in group.rules></rule> </group> 

즉 rule (scope.addRules) scope.rules.push()는 물론 중단됩니다. 이 오류를 무시할 수있는 방법은 무엇입니까? 나는 scope.groups.rule.push()를 사용할 수 없기 때문에 말할 수 없다. – allencoded

+0

그래서 Rule을 그룹 지시어 안에 추가하면 각 그룹에는 객체의 배열 인 속성 규칙이 있어야한다. ng-click = "addRule (group)"과 같이 그룹 객체를 전달하면 컨트롤러에서 함수에 액세스 할 수 있습니다. $ scope.addRule = function (group) {group.rules.push()}; 또한 규칙이 객체의 객체가 아닌지 확인하십시오 그렇지 않으면 다르게해야합니다 group.rules [somekey] = someObject – btm1