내 HTML :AngularJS와 - 컨트롤러의 결합 체크 박스 수집
<ol ng-model="gcwr.checked" ng-repeat="gcwr in gcwrs" id="gcwr">
<label class="checkbox" for="{{gcwr.Id}}">
{{gcwr.Description}}
<input ng-model="gcwr.checked" type="checkbox" /></label>
</ol>
내 컨테이너 컨트롤러 :
// initialize section
$scope.gcwrs = API.GetGCWRs();
// in the save/submit function
var newContainer = $scope.newContainer;
var myGCWRS;
var tmp = angular.forEach($scope.gcwrs, function (gcwr) {
myGCWRS += gcwr.checked ? gcwr : null;
});
newContainer.GCWRs = [
angular.copy(myGCWRS)
];
문제 :
GCWRs는 형태로 채우고있다 , 나는 ch를 모으는데있어서 잘못된 것을하고있다. newContainer에 컬렉션을 추가하는 submit/save 함수 광고에서 gcwrs를 호출합니다.
아이디어가 있으십니까?
- 각 세계 :(이 해결
에서 결코 지루한 하루 :.
엉덩이! TGIF에서 어떤 고통 지금은 이유가 있기 때문에
여기에 솔루션입니다 :
var selectedGCWRs = [];
var tmp = angular.forEach($scope.gcwrs, function (gcwr) {
if (gcwr.checked) {
selectedGCWRs.push(gcwr);
}
});
newContainer.GCWRs = selectedGCWRs;
.... then go on and save the newContainer.
(죄송합니다, 나는 원래의 게시물에서 일부 이름을 변경) [참고 : angular.copy를 사용했다면 ng-repeat에서 생성 한 $$ 해시 키가 제거되지 않았을 것입니다. 따라서 서버는 서버의 모델 클래스와 일치하지 않는 추가 속성, 즉 $$ hashkey를 가지므로이 컬렉션을 거부했을 것입니다. 단순히 컨테이너 컬렉션을 통과함으로써, $$ HASHKEYS 멀리 제거하고 서버는 행복하다.]
왜 질문 안에 대답 ..? – redben