allow_add
또는 allow_remove
을 지정하면 컬렉션에 모든 요소 수가 포함될 수 있습니다 (count
으로 지정된 최소값).
컬렉션에 폼을 추가 한 후에는 클릭 할 때 템플릿을 기반으로 다른 요소를 추가하는 함수를 호출하는 버튼을 추가해야합니다.
<button onclick="return add_category()">Add a new category</button>
및
<script>
function add_category() {
var currentCount = $('form > fieldset > fieldset').length;
var template = $('form > fieldset > span').data('template');
template = template.replace(/__index__/g, currentCount);
$('form > fieldset').append(template);
return false;
}
</script>
가하는 제거 버튼을 추가 템플릿에 단추를 추가하려면 위의 기능을 변경 및 제거 기능을 만들려면 :
을 수동에서
<script>
function add_category() {
var currentCount = $('form > fieldset > fieldset').length;
var template = $('form > fieldset > span').data('template');
template = template.replace(/__index__/g, currentCount)
.replace('</fieldset>', '<button onclick="return remove_category(this)">Remove</button></fieldset>');
$('form > fieldset').append(template);
return false;
}
function remove_category(el) {
$(el).parent().remove();
}
</script>
안녕하세요! 귀하의 질문은 공식 문서 (https://framework.zend.com/manual/2.4/en/modules/zend.form.collections.html#adding-new-elements-dynamically)에서 적절한 답변을 제공합니다. 보지 못했거나 더 구체적인 질문이 있으시면 더 자세한 정보를 보내주십시오. –