HTML テーブルの PHP クラス: 奇妙な属性の割り当て
P粉384679266
P粉384679266 2023-09-06 00:38:07
0
1
362

HTML テーブルを構築するクラスには、テーブルをレンダリングするこのメソッドがあります。特定の条件 (インデント、終了タグ、データ表現など) での HTML 属性の割り当てを除いて、すべてが正常に動作します。セルのデータを設定するときは、setData() を呼び出して 3 つのパラメーターを受け取り、次のように使用します。 3 番目のパラメーター (セル プロパティ) をどのように設定しているかに注目してください:

メソッド定義:

public function setData( 配列 $data、 配列 $row_attributes = [], 配列 $cell_attributes = [] ): ブール値 { // コード }

電話:

$table->setData( $ページネーション->結果セット、 [], // 行属性 array( // セルの属性 array(), // 行 1 (インデックス 0) array( // row2 (インデックス 1) ["id"=>"R2C1id"], // 行 2、セル 1 ["id"=>"R2C2id", "onclick"=>"R2C2_onclick();"], // 行 2、セル 2 )、 array( // 行 3 []、 []、 ["id"=>"R3C3id", "selected"=>"selected"], // 行 3、セル 3 []、 []、 []、 [] ) ) );

この例では、テーブルには 7 つの列があります。

ここでは HTML 出力が表示されます。 2 行目と 3 行目のセルのプロパティに注目してください:

1
Consumidor Final
Consumidor Final
1
2
Prueba SRL
Tu Prueba
12345678901
1
3
Otra Prueba SA
Prueba 2
12345678902
1

これは、これらすべてを行うために使用するコードです。セルのレンダリングのコード スニペットとプロパティの処理方法を示します。

セルのレンダリング:

// セルを処理します $row_counter = 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("セル", $row_counter, $cell_counter), 3 ); } $cell_counter ; } // $cell_counter ; // 行を保持するために空のセルを完成させます: 完全な行にホバーします while ($cell_counter < $col_count) { $row_build .= $this->getHtmlDiv( $html_cell_class、 「」、 $this->getHtmlAttributes("セル", $row_counter, $cell_counter), 3 ); $cell_counter ; } $body_build .= $this->getHtmlDiv( $html_row_class、 $row_build、 $this->getHtmlAttributes("row", $row_counter, 0), 2、 真実 ); $row_counter ; }

属性メソッド:

プライベート関数 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 === "セル") { if (array_key_exists($column, $this->html_attributes[$section][$row])) { return $this->html_attributes[$section][$row][$column]; } } return $this->html_attributes[$section][$row]; } } 戻る []; }

何が問題ですか?ありがとう。

P粉384679266
P粉384679266

全員に返信 (1)
P粉349222772

さて、質問を投稿してコードを選択すると、答えが表示されました。メソッドgetHtmlAttributes()else条件がありません。

リーリー
いいねを押す+0
    最新のダウンロード
    詳細>
    ウェブエフェクト
    公式サイト
    サイト素材
    フロントエンドテンプレート
    私たちについて 免責事項 Sitemap
    PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!