내 문제는 간단합니다.단추를 클릭 할 때 중첩 된 형식 양식의 상태를 읽기 전용으로 변경하는 방법
내가 가진 것들.
- 데이터 (JSON)를 사용하여 만든 양식 (형식적)이 백엔드에서 받았습니다.
- 양식이 다중 레벨 중첩 (현재 두 레벨 중첩)됩니다.
- 버튼을 클릭하면 양식에 다른 요소를 추가하는 모든 중첩 된 양식 요소와 연결된 리피터가 있습니다.
- 양식 요소의 상태를 readOnly로 토글하는 버튼이 페이지 상단에 있습니다. 내가
에 직면하고있다
문제 - I 버튼을 클릭하면, 형태 요소의 상태는를 중첩하는 것을 제외하고 readOnly 인, 로 변경합니다.
내가 버튼을 클릭 --When
이, 내 양식의 모든 단일 요소가 읽기 전용으로 상태가 중첩 여부를 변경해야 원하는 것은.
다음은 컨트롤러입니다 ... JS-Bin 링크가 뒤 따른다. 사전
P.S.에서
app.controller('MainCtrl', function MainCtrl(formlyVersion) {
var vm = this;
vm.onSubmit = onSubmit;
vm.exampleTitle = 'Nested Repeating Section';
vm.options = {
formState: {
readOnly: true
}
};
init();
vm.originalFields = angular.copy(vm.fields);
function onSubmit() {
alert(JSON.stringify(vm.model), null, 2);
}
function init() {
vm.fields = [{
key: 'name',
type: 'input',
templateOptions: {
label: 'Name',
required: true,
minlength: 5,
maxlength: 25
}
}, {
key: 'description',
type: 'textarea',
templateOptions: {
label: 'Description',
rows: 5,
maxlength: 100
}
}, {
wrapper: 'panel',
templateOptions: {
label: 'Cars'
},
fieldGroup: [{
type: 'repeatSection',
key: 'cars',
templateOptions: {
btnText: '+',
fields: [{
wrapper: 'panel',
templateOptions: {
label: 'New car'
},
fieldGroup: [{
key: 'carname',
type: 'input',
templateOptions: {
label: 'Name',
required: true,
maxlength: 25
}
}, {
key: 'cardesc',
type: 'input',
templateOptions: {
label: 'Description',
maxlength: 50
}
}]
}]
}
}]
}];
}
});
http://jsbin.com/sunocaf/edit?html,js,output
감사합니다 - 나는 형식적인 공식 웹 사이트에서 예를 들었다.
답변을 주신 MattE에게 감사드립니다. 한 달 전에 작동하게 만들었 기 때문에 나는 당신의 방식을 사용하지 않았지만. 내가 사용한 솔루션을 게시 할 예정입니다. 다시 한 번 감사드립니다 ... 건배 !! –