国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

PHP-Klasse für HTML-Tabelle: seltsame Attributzuweisung
P粉384679266
P粉384679266 2023-09-06 00:38:07
0
1
602
<p>In der Klasse, die die HTML-Tabelle erstellt, habe ich diese Methode, die die Tabelle rendert. Bis auf die Zuweisung von HTML-Attributen unter bestimmten Bedingungen (Einrückung, schlie?ende Tags, Datendarstellung usw.) funktioniert alles einwandfrei. Wenn ich die Zelldaten festlege, rufe ich setData() auf, um die drei Parameter zu empfangen und sie so zu verwenden. Beachten Sie, wie ich den dritten Parameter (Zelleneigenschaft) festlege: </p> <p><strong>Methodendefinition: </strong></p> <pre class="brush:php;toolbar:false;">public function setData( Array $data, Array $row_attributes = [], Array $cell_attributes = [] ): bool { // der Code }</pre> <p><strong>Aufruf: </strong></p> <pre class="brush:php;toolbar:false;">$table->setData( $pagination->resultset, [], // Zeilenattribute array( // Zellattribute array(), // Zeile 1 (Index 0) array( // Zeile2 (Index 1) ["id"=>"R2C1id"], // Zeile 2, Zelle 1 ["id"=>"R2C2id", "onclick"=>"R2C2_onclick();"], // Zeile 2, Zelle 2 ), array( // Zeile 3 [], [], ["id"=>"R3C3id", "selected"=>"selected"], // Zeile 3, Zelle 3 [], [], [], [] ) ) );</pre> <p>In diesem Beispiel hat die Tabelle sieben Spalten. </p> <p>Hier sehen Sie die HTML-Ausgabe. Beachten Sie die Zelleigenschaften der zweiten und dritten Zeile: </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'>Consumidor Final</div> <div class='table-row-cell'>Consumidor Final</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='Array' 1='Array'>Tu Prueba</div> <div class='table-row-cell' 0='Array' 1='Array'>12345678901</div> <div class='table-row-cell' 0='Array' 1='Array'>1</div> <div class='table-row-cell' 0='Array' 1='Array'></div> <div class='table-row-cell' 0='Array' 1='Array'></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>Das ist der Code, den ich für all das verwende. Ich zeige Ihnen den Codeausschnitt für das Rendern von Zellen und wie Sie mit Eigenschaften umgehen. </p> <p><strong>Zellenrendering: </strong></p> <pre class="brush:php;toolbar:false;">// Zellen verarbeiten $row_counter = 0; foreach ($this->data as $data) { // Zeile $row_build = ""; $cell_counter = 0; foreach ($data as $cell_data) { // cell if ($cell_counter < $col_count) { $row_build .= $this->getHtmlDiv( $html_cell_class, $cell_data ?? "", $this->getHtmlAttributes("cell", $row_counter, $cell_counter), 3 ); } $cell_counter++; } // $cell_counter++; // Leere Zellen vervollst?ndigen, um Zeile beizubehalten: Bewegen Sie den Mauszeiger über die gesamte Zeile while ($cell_counter < $col_count) { $row_build .= $this->getHtmlDiv( $html_cell_class, "", $this->getHtmlAttributes("cell", $row_counter, $cell_counter), 3 ); $cell_counter++; } $body_build .= $this->getHtmlDiv( $html_row_class, $row_build, $this->getHtmlAttributes("row", $row_counter, 0), 2, WAHR ); $row_counter++; }</pre> <p><strong>Attributmethoden:</strong></p> <pre class="brush:php;toolbar:false;">private Funktion getHtmlAttributes(string $section, int $row, int $column): Array { if (count($this->html_attributes[$section]) > 0) { if (array_key_exists($row, $this->html_attributes[$section])) { if ($section === "cell") { if (array_key_exists($column, $this->html_attributes[$section][$row])) { return $this->html_attributes[$section][$row][$column]; } } return $this->html_attributes[$section][$row]; } } zurückkehren []; }</pre> <p>Was ist los? Danke. </p>
P粉384679266
P粉384679266

Antworte allen(1)
P粉349222772

好吧,當(dāng)我發(fā)布問題并選擇代碼時,答案出現(xiàn)了。在方法 getHtmlAttributes() 中,缺少 else 條件。

private function getHtmlAttributes(string $section, int $row, int $column): array
{

    if (count($this->html_attributes[$section]) > 0) {
        if (array_key_exists($row, $this->html_attributes[$section])) {
            if ($section === "cell") {
                if (array_key_exists($column, $this->html_attributes[$section][$row])) {
                    return $this->html_attributes[$section][$row][$column];
                } else { // <-- this 
                    return [];
                }
            }
            return $this->html_attributes[$section][$row];
        }
    }
    return [];
}
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage