2012-11-03 4 views
7

토픽에 많은 질문 (1 대 다수)이 있고 질문에 많은 답변 (1 대 다수)이있는 데이터 구조가 있습니다.심포니 2 형식, 임베디드 컬렉션에 컬렉션 포함

토픽 양식에 질문을 임베디드 컬렉션으로 설정했으며 cookbook entry 덕분에 모든 기능이 100 % 작동합니다.

질문 양식에 답변 양식 모음을 포함시키기 위해이 도구를 개발하려고하면 문제가 발생합니다.

최상위 레벨의 프로토 타입 양식을 포함하는 데이터 프로토 타입 속성에는 양식의 전체 깊이가 포함되어 있으므로 질문 및 답변의 프로토 타입이 포함됩니다. 그러나 각 레벨에 대해 동일한 자리 표시 자 __name__을 사용합니다.

<div id="topic_questions___name__"> 
<div class="control-group"> 
    <label for="topic_questions___name___questionText" class="control-label">question</label> 
    <div class="form-row-errors"></div> 
    <div class="controls"> 
     <textarea id="topic_questions___name___questionText" name="topic[questions][__name__][questionText]" required="required" class="input-block-level"></textarea> 
    </div> 
</div> 
<div class="control-group"> 
    <label class="control-label">answers</label> 
    <div class="controls"> 
     <div id="topic_questions___name___answers"  data-prototype="&lt;div class=&quot;control-group&quot;&gt;&lt;label class=&quot;control-label&quot;&gt;__name__label__&lt;/label&gt;&lt;div class=&quot;controls&quot;&gt;&lt;div id=&quot;topic_questions___name___answers___name__&quot;&gt;&lt;div class=&quot;control-group&quot;&gt;&lt;label for=&quot;topic_questions___name___answers___name___answerText&quot; class=&quot;control-label&quot;&gt;option&lt;/label&gt;&lt;div class=&quot;form-row-errors&quot;&gt;&lt;/div&gt;&lt;div class=&quot;controls&quot;&gt;&lt;input type=&quot;text&quot; id=&quot;topic_questions___name___answers___name___answerText&quot; name=&quot;topic[questions][__name__][answers][__name__][answerText]&quot; required=&quot;required&quot; maxlength=&quot;255&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;input type=&quot;hidden&quot; id=&quot;topic_questions___name___answers___name___sortOrder&quot; name=&quot;topic[questions][__name__][answers][__name__][sortOrder]&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"></div> 
    </div> 
</div> 

당신은 내가 추측 바닥에서 정말 긴 줄을 볼 수 있습니다

는 응답 양식에 대한 프로토 타입 프로토 타입 (!)입니다. [__name__]과 관련된 질문 만 대체 할 수있는 방법은 없습니다. 응답과 관련된 질문은 대체 할 수 없습니다. 물론 질문 형식의 실제 인스턴스를 생성하는 데이터 프로토 타입 도움말 형태로 만들어집니다 이렇게하면 같은 값으로 __name__의 모든 인스턴스를 대체 할 때

var newForm = prototype.replace(/__name__/g, collectionHolder.children().length); 
이 , 그것은 정상이

수행

이미 모든 자리 표시자를 교체했습니다.

은 내가 진짜 질문 양식

<div class="control-group"> 
<label class="control-label">1label__</label> 
<div class="controls"> 
    <div id="topic_questions_1_answers_1"> 
     <div class="control-group"> 
      <label for="topic_questions_1_answers_1_answerText" class="control-label">option</label> 
      <div class="form-row-errors"></div> 
      <div class="controls"> 
       <input type="text" id="topic_questions_1_answers_1_answerText" name="topic[questions][1][answers][1][answerText]" required="required" maxlength="255" /> 
      </div> 
     </div> 
    </div> 
</div> 

당신이 볼 수 있듯이, __name__ 자리 나던 기능에서을 추가 클릭 한 경우 데이터 프로토 타입, 도움말 양식의 모습입니다 모두 - 질문 양식을 만들 때 이미 질문 양식의 수로 대체되었습니다.

Symfony가 제공하는 메커니즘을 사용하여 이러한 종류의 다중 깊이 포함 된 컬렉션을 구현할 수 있습니까?

각 '레벨'에 대해 동일한 자리 표시자를 사용하려고하면 어떻게 볼 수 없습니다.

답변