드롭 다운 대체를 위해 작성한 지시어에 정말 이상한 동작이 있습니다. 사용 된 모델은 자식 노드를 사용하여 무한대로 중첩 될 수 있습니다. 지시문이 (HAML-코드)와 같이 포함되어 있습니다 : 내가 지금까지 발생으로AngularJS : 지시문의 템플릿이 올바르게 렌더링되지 않습니다.
.control-group
-# use the angular directive "dropdown-tree" that can handle unlimited nested models!
.controls{ "dropdown-tree" => "", "ng-model" => "categories_as_tree", "current-value" => "currentCategory", "dropdown-placeholder" => "choose category", "ng-disabled" => "!categories || categories.length==0", "on-change"=>"fetchProducts(category)" }
%h4 Products
.control-group
.controls{ "dropdown-tree" => "", "ng-model" => "products_as_tree", "current-value" => "currentProduct", "dropdown-placeholder" => "choose product", "ng-disabled" => "!products || products.length==0" }
이 모델은 absolulately 제대로 작동하고! 디버그 뷰 또는 console.log 또는 $ log를 통해 얻을 수 있지만 지시문 렌더링은 두 번 또는 곱해진 항목을 표시하는 데 엉망이되어 드롭 다운을 몇 번 전환했는지에 따라 달라집니다.
커피 스크립트는 쉽게 코드 인 다음과 같습니다 지침의
# use array -> being resistend against uglifiers mangle
mymodule.directive 'dropdownTree', [ ->
return {
templateUrl: '/angular/templates/dropdown_tree'
,
#require: 'ngModel', # don't need that so far, we keep things simple!
scope: {
ngModel: '=',
dropdownPlaceholder: '@',
currentValue: '=',
ngDisabled: '=',
onChange: '&'
},
link: (scope, element, attr, ngModelCtrl) ->
# fake the ng-change
scope.$watch('currentValue', ->
scope.onChange()
, true)
scope.selectValue = (value) ->
scope.currentValue = value
}
]
뷰 템플릿 코드가 HAML로 작성하고 다음과 같습니다되는 레일 컨트롤러 에 의해 전달됩니다. 이 자식 노드가 존재하는 경우 무한 중첩을 사용
.btn-group{ :name => "FIXME", "ng-required" => "true" }
%a.btn.btn-default.dropdown-toggle{ "data-toggle" => "dropdown", href: "#", "ng-disabled"=>"ngDisabled" }
{{currentValue.name || dropdownPlaceholder }}
%span.caret
%ul.dropdown-menu{ "ng-show" => "!ngDisabled" }
%div{ "ng-repeat" => "model in ngModel", "ng-include" => "'node.html'" }
%script{ :type => "text/ng-template", :id => "node.html" }
%li{ "ng-click" => "selectValue(model)" }
%a
{{model.name}}
%ul{ "ng-repeat" => "model in model.children", :style => "margin-left: 10px;" }
%div{ "ng-include" => "'node.html'" }
내가 두 번째 드롭 다운이 올바르게보기를 업데이트하지 않습니다이 단지 하나에 문제가 없었어요,이 모델은 않습니다. 나는 합법적이지 않은 것을 당신이 도울 수 있거나 볼 수 있는지 궁금합니다.
종류와 관련, 알렉스
궁금한 점은 왜 변경 대신 변경을 사용합니까? – jpmorin
나는 HAML에 익숙하지 않지만 들여 쓰기를 한 다음, 이것이 나의 이해이다. 첫 번째 단계는'ul' 안에서 당신의 첫 단계를 반복하고,'div'는'li'를 넣는다. 하위 레벨에서'li'의 형제 인'ul'을 반복하고'ul'에서'sub'를 사용하여 다음 하위 레벨을 시작합니다 ... 당신의 계층 구조는 다음과 같습니다 : 'ul > div [loop]> [li> aul [loop]> div> [li> aul [loop]> div ...' AFAIK, 유효한 HTML이 아닙니다. 'ul'의 유일한 유효한 요소는'li'입니다. – jpmorin
값이 사용자 지정 범위에서 호출되는 콜백으로 지시문에 의해 읽혀지기 때문에 변경시 사용했습니다. $ watch ... ng-change 때문에 지시어의 다른 사용자에 대해 ng-change를 혼합하고 싶지 않았습니다. 네이티브 지시어입니다 ... 옙, 나도 나쁜 html입니다. 그 이유는 올바른 항목을 수신 할 수있는 일부 블록을 추가하기 위해서였습니다. 아래에서 귀하의 게시물을 확인하겠습니다. 정말 고맙습니다. – sp33c