2015-09-28 77 views
0

我讀過選定的jquery http://harvesthq.github.io/chosen/。好吧,我想要「隱藏搜索單選」作爲相同的例子(例如在guthub /上面選擇),如FLAG=false隱藏它們。我該怎麼做?如何隱藏搜索單選select jquery?

var data = [{ 
 
    "BU_ID": "B01", 
 
     "BU_NAME": "Agro Feed", 
 
     "BU_DES": "Agro Feed", 
 
     "EDIT_DATE": "2015-05-05T00:00:00", 
 
     "EDIT_BY": "", 
 
     "FLAG": true 
 
}, { 
 
    "BU_ID": "B02", 
 
     "BU_NAME": "Agro Farm", 
 
     "BU_DES": "Agro Farm", 
 
     "EDIT_DATE": "2015-05-05T00:00:00", 
 
     "EDIT_BY": "", 
 
     "FLAG": false 
 
},{ 
 
    "BU_ID": "B03", 
 
     "BU_NAME": "Agro Food", 
 
     "BU_DES": "Agro Food", 
 
     "EDIT_DATE": "2015-05-05T00:00:00", 
 
     "EDIT_BY": "", 
 
     "FLAG": true 
 
} 
 
      ]; 
 

 
$("#cb_info").empty(); 
 
$.each(data, function (idx, obj) { 
 
    $("#cb_info").append('<option value="' + obj.BU_ID + '">' + obj.BU_NAME + '</option>'); 
 
}); 
 
$("#cb_info").chosen({ width: "auto" }); 
 
$("#cb_info").trigger("chosen:updated");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="http://cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.css" rel="stylesheet"/> 
 
<script src="http://cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.jquery.js"></script> 
 
<select id="cb_info"></select>

謝謝你們。

+1

還不是很清楚..你可以詳盡地用一個例子單SELECT_ _hide搜索? –

+0

你想隱藏有'Flag:false'的選項嗎? –

+0

親愛的@MKA,完全如您所說。 –

回答

1

你的問題是不那麼清楚。但是,如果你想要使用FLAG禁用項目:false,那麼只需爲這些選項指定禁用屬性即可。

var data = [{ 
 
    "BU_ID": "B01", 
 
     "BU_NAME": "Agro Feed", 
 
     "BU_DES": "Agro Feed", 
 
     "EDIT_DATE": "2015-05-05T00:00:00", 
 
     "EDIT_BY": "", 
 
     "FLAG": true 
 
}, { 
 
    "BU_ID": "B02", 
 
     "BU_NAME": "Agro Farm", 
 
     "BU_DES": "Agro Farm", 
 
     "EDIT_DATE": "2015-05-05T00:00:00", 
 
     "EDIT_BY": "", 
 
     "FLAG": false 
 
},{ 
 
    "BU_ID": "B03", 
 
     "BU_NAME": "Agro Food", 
 
     "BU_DES": "Agro Food", 
 
     "EDIT_DATE": "2015-05-05T00:00:00", 
 
     "EDIT_BY": "", 
 
     "FLAG": true 
 
} 
 
      ]; 
 

 
$("#cb_info").empty(); 
 
$.each(data, function (idx, obj) { 
 
var status = (!obj.FLAG)?'disabled':''; 
 
    $("#cb_info").append('<option '+status+' value="' + obj.BU_ID + '">' + obj.BU_NAME + '</option>'); 
 
}); 
 
$("#cb_info").chosen({ width: "auto" }); 
 
$("#cb_info").trigger("chosen:updated");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<link href="http://cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.css" rel="stylesheet"/> 
 
<script src="http://cdnjs.cloudflare.com/ajax/libs/chosen/1.0/chosen.jquery.js"></script> 
 
<select id="cb_info"></select>

1
var data = [{ 
    "BU_ID": "B01", 
     "BU_NAME": "Agro Feed", 
     "BU_DES": "Agro Feed", 
     "EDIT_DATE": "2015-05-05T00:00:00", 
     "EDIT_BY": "", 
     "FLAG": true 
}, { 
    "BU_ID": "B02", 
     "BU_NAME": "Agro Farm", 
     "BU_DES": "Agro Farm", 
     "EDIT_DATE": "2015-05-05T00:00:00", 
     "EDIT_BY": "", 
     "FLAG": false 
}, { 
    "BU_ID": "B03", 
     "BU_NAME": "Agro Food", 
     "BU_DES": "Agro Food", 
     "EDIT_DATE": "2015-05-05T00:00:00", 
     "EDIT_BY": "", 
     "FLAG": true 
}]; 

$("#cb_info").empty(); 
$.each(data, function (idx, obj) { 
    if (obj.FLAG === true) { 
     $("#cb_info").append('<option value="' + obj.BU_ID + '">' + obj.BU_NAME + '</option>'); 
    } 
}); 

只需添加一個條件if (obj.FLAG === true) { 只有真正標誌將在列表上添加爲此你不需要隱瞞什麼

DEMO

修訂

demo

+0

Dear @ Pekka,作爲你的回答,我知道但是在這裏,我想顯示所有的(3選項:2選項啓用和1選項可見) –

+0

@BrianCrist '例如FLAG = false隱藏他們'因爲我明白這個你想隱藏,如果國旗是假的。你能解釋你真正想要的嗎? – guradio

+0

尊敬的@Pekka,感謝您的回答。我創建了一個答案,從傑克rudetsky –