如何隐藏对单个 select 选择的 jquery 的搜索?

How to hide search on single select chosen jquery?

我在 http://harvesthq.github.io/chosen/ 阅读了 chosen jquery 。好的,我想 "Hide Search on Single Select" 作为相同的示例(上面 guthub/chosen 中的示例),例如 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) {
    $("#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>

谢谢大家。

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) { 只有带有 true 的标志才会被添加到列表中因此你不需要隐藏任何东西

DEMO

已更新

demo

你的问题不是很清楚。但是,如果您想要禁用带有 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>