LoginSignup
2
3

More than 5 years have passed since last update.

デバック用データ定義とセレクトボックスを使った使用方法

Posted at

備忘録。
データ定義は別のJSファイルにしておくと管理が楽ですな。

<select  id="target"></select>

/*
コンテナ用変数「my」の定義及びデバッグ用データ定義
(*)my.debug == 1の時にdebugデータを使用する
*/
var my = {
    "debug" : 1,            // 0:API使用 1:debugデータ使用
};

$(function(){
        my.setList( my.data.TESTDATA ,"target");
});

/* リスト設定
 * json : 渡されるデータ json形式
 *      { "コード" : "表示データ" } の形式で渡される
 * id : 設定するリストの要素id
 */
my.setList = function( json,id ){
    $.each( json, function( i, v ){
        $( "#"+id ).append( '<option value="' + i + '">' + v + '</option>' );
    });

// debug用データ定義 my.debugが1の時有効にする
// 全て コード:データの組み合わせ
if( my.debug == 1 ){
    my.data = {
        "TESTDATA" : {
        "":"選択してください",
        "0001":"hoge",
        "0002":"moge",
        }
    };
}
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3