我已经在http://harvesthq.github.io/chosen/选择了jquery。好的,我想"隐藏单一选择的搜索"同样的例子(例如guthub /上面选择的例子),例如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");
&#13;
<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>
&#13;
谢谢你们。
答案 0 :(得分: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) {
只有带有true的标志才会被添加到列表中,因此您不需要隐藏任何内容
<强>已更新强>
答案 1 :(得分:1)
你的问题不是那么清楚。但是,如果你想要的是禁用带有FLAG的项:false,那么只需为这些选项指定disabled属性。
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");
&#13;
<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>
&#13;