掲示板をつくってみる2
前回のものに簡単なページャー機能つけてみました。
変更したのはFlex側のみ
//表示するオブジェクトをdisplayAryにセット private function setDisplay():void{ //DataGrid上に表示する記事数の計算 var max:uint = artAry.length - 10*offset; if(max > 10) max = 10; //一度空にする displayAry.removeAll(); //表示する記事をdisplayAryに格納 for(var i:uint = 0; i < max; i++){ displayAry.addItem(artAry[i+offset*10]); } } //次の10件を表示 private function next():void{ offset++; //offsetの値が範囲外にならないようにする if(offset > int((artAry.length-1)/10)) offset = int((artAry.length-1)/10); setDisplay(); } //前の10件を表示 private function prev():void{ offset--; //offsetの値が範囲外にならないようにする if(offset < 0) offset = 0; setDisplay(); } //最新の10件を表示 private function newest():void{ offset=0; setDisplay(); }
変数の説明
artAry: 全記事を格納している配列
displayAry: DataGrid上に表示する記事を格納する配列
offset: 現在表示している位置。例えば1〜10件目の記事を表示しているなら0。21〜30件目なら2。
全体のソース