>  Q&A  >  본문

HTML 테이블용 PHP 클래스: 이상한 속성 할당

<p>HTML 테이블을 작성하는 클래스에는 테이블을 렌더링하는 이 메소드가 있습니다. 특정 조건(들여쓰기, 닫는 태그, 데이터 표현 등)에서 HTML 속성 할당을 제외하고 모든 것이 잘 작동합니다. 셀 데이터를 설정할 때 setData()를 호출하여 3개의 매개변수를 전달받아 이렇게 사용합니다. 세 번째 매개변수(셀 속성)를 어떻게 설정했는지 살펴보세요. </p> <p><strong>방법 정의: </strong></p> <pre class="brush:php;toolbar:false;">공용 함수 setData( $data 배열, 배열 $row_attributes = [], 배열 $cell_attributes = [] ): 부울 { // 코드 }</pre> <p><strong>전화: </strong></p> <pre class="brush:php;toolbar:false;">$table->setData( $pagination->resultset, [], // 행 속성 array( // 셀 속성 array(), // 행 1(인덱스 0) array( // 행2(인덱스 1) ["id"=>"R2C1id"], // 행 2, 셀 1 ["id"=>"R2C2id", "onclick"=>"R2C2_onclick();"], // 행 2, 셀 2 ), array( // 3행 [], [], ["id"=>"R3C3id", "selected"=>"selected"], // 행 3, 셀 3 [], [], [], [] ) ) );</pre> <p>이 예에서 테이블에는 7개의 열이 있습니다. </p> <p>여기서 HTML 출력을 볼 수 있습니다. 두 번째와 세 번째 행의 셀 속성을 확인하세요. </p> <pre class="brush:php;toolbar:false;"><div class='table-body'> <div class='table-row'> <div class='table-row-cell'>1</div> <div class='table-row-cell'>소비자 최종</div> <div class='table-row-cell'>소비자 최종</div> <div class='table-row-cell'></div> <div class='table-row-cell'>1</div> <div class='table-row-cell'></div> <div class='table-row-cell'></div> </div> <div class='table-row'> <div class='table-row-cell' id='R2C1id'>2</div> <div class='table-row-cell' id='R2C2id' onclick='R2C2_onclick();'>Prueba SRL</div> <div class='table-row-cell' 0='배열' 1='배열'>투 프루에바</div> <div class='table-row-cell' 0='배열' 1='배열'>12345678901</div> <div class='table-row-cell' 0='배열' 1='배열'>1</div> <div class='table-row-cell' 0='배열' 1='배열'></div> <div class='table-row-cell' 0='배열' 1='배열'></div> </div> <div class='table-row'> <div class='table-row-cell'>3</div> <div class='table-row-cell'>Otra Prueba SA</div> <div class='table-row-cell' id='R3C3id' selected='selected'>Prueba 2</div> <div class='table-row-cell'>12345678902</div> <div class='table-row-cell'>1</div> <div class='table-row-cell'></div> <div class='table-row-cell'></div> </div> </div></pre> <p>이것은 제가 이 모든 작업을 수행하는 데 사용하는 코드입니다. 셀 렌더링을 위한 코드 조각과 속성을 처리하는 방법을 보여 드리겠습니다. </p> <p><strong>셀 렌더링: </strong></p> <pre class="brush:php;toolbar:false;">// 셀 처리 $행_카운터 = 0; foreach ($this->data as $data) { // 행 $row_build = "";; $cell_counter = 0; foreach ($data as $cell_data) { // 셀 if ($cell_counter < $col_count) { $row_build .= $this->getHtmlDiv( $html_cell_class, $cell_data "", $this->getHtmlAttributes("cell", $row_counter, $cell_counter), 삼 ); } $cell_counter++; } // $cell_counter++; // 행을 보존하기 위해 빈 셀을 완성합니다. 전체 행에 마우스를 올리면 됩니다. while ($cell_counter < $col_count) { $row_build .= $this->getHtmlDiv( $html_cell_class, "", $this->getHtmlAttributes("cell", $row_counter, $cell_counter), 삼 ); $cell_counter++; } $body_build .= $this->getHtmlDiv( $html_row_class, $row_build, $this->getHtmlAttributes("행", $row_counter, 0), 2, 진실 ); $row_counter++; }</pre> <p><strong>속성 방법:</strong></p> <pre class="brush:php;toolbar:false;">비공개 함수 getHtmlAttributes(string $section, int $row, int $column): 배열 { if (count($this->html_attributes[$section]) > 0) { if (array_key_exists($row, $this->html_attributes[$section])) { if ($section === "셀") { if (array_key_exists($column, $this->html_attributes[$section][$row])) { return $this->html_attributes[$section][$row][$column]; } } return $this->html_attributes[$section][$row]; } } 반품 []; }</pre> <p>무슨 일이 있나요? 감사해요. </p>
P粉384679266P粉384679266382일 전398

모든 응답(1)나는 대답할 것이다

  • P粉349222772

    P粉3492227722023-09-06 20:10:33

    자, 질문을 올리고 코드를 선택하니 답이 나오더라구요. 방법 getHtmlAttributes() 中,缺少 else 상태입니다.

    으아악

    회신하다
    0
  • 취소회신하다