Bootstrap Multiselect 设置 option

 $.ajax({
        type: 'post',
        url: "helper/ajax_search.php",
        data: {models: decodeURIComponent(brands)},
        dataType: 'json',
        success: function(data) {
            $('select.multiselect').empty();
$('select.multiselect').append( $('<option></option>') .text('alle') .val('alle') ); $.each(data, function(index, html) { $('select.multiselect').append( $('<option></option>') .text(html.name) .val(html.name) ); }); $('.multiselect').multiselect('rebuild') }, error: function(error) { console.log("Error:"); console.log(error); } });

<extend name="Public/base" />
<block name='style'>
<style type="text/css">
.sctext{ width:700px; height: 300px;}
</style>
</block>
<block name="body">
<div class="main-title cf">
<h2>渠道授权页面</h2>
</div>
<br/>

<!-- 表单 -->
<form id="form" action="{:U('/Admin/System/User/userChannelAuth')}" method="post" class="form-horizontal">
<input id="user_id" name="user_id" type="hidden" value="{$_GET['id']}">
<input id="user_name" name="user_name" type="hidden" value="{$_GET['name']}">
<div class="form-item">
<label class="item-label">平台类型<span class="check-tips">(请勾选平台类型)</span></label>
<div>
<select id="platform_type" name="platform_type[]" multiple="multiple">
<volist name="platform_type" id="vo">
<in name="vo.type_id" value="$platform_type_id">
<option value="{$vo.type_id}" class="row-select" selected="selected">{$vo.type_name}</option>
<else/>
<option value="{$vo.type_id}" class="row-select" >{$vo.type_name}</option>
</in>
</volist>
</select>
</div>
</div>
<br/>
<div class="form-item">
<label class="item-label">渠道<span class="check-tips">(请勾选渠道)</span></label>
<div>
<select id="channel" name="channel[]" multiple="multiple">
<volist name="ChannelInfo_data" id="vo">
<in name="vo.id" value="$channel_id">
<option value="{$vo.id}" class="row-select" selected="selected">{$vo.cn_name}</option>
<else/>
<option value="{$vo.id}" class="row-select" >{$vo.cn_name}</option>
</in>
</volist>
</select>
</div>
</div>
<br/>
<div class="form-item">
<label class="item-label">授权用户:{$_GET["name"]}<span class="check-tips"></span></label>

</div>
<br/>
<div class="form-item">
<button type="submit" class="btns submit-btn ajax-post" target-form="form-horizontal">授 权</button>
</div>
</form>
</block>

<block name="script">
<script type="text/javascript" charset="utf-8">
//导航高亮
highlight_subnav('{:U('/Admin/System/User/index')}');

highlight_subnav('{:U('saveServer')}');
Think.setValue('lua','{:I('lua')}');
$('#platform_type').multiselect(
{
enableFiltering: true,
nonSelectedText:'请选择平台类型',
filterPlaceholder:'搜索',
nSelectedText:'项被选中',
includeSelectAllOption:true,
selectAllText:'全选/取消全选',
allSelectedText:'已选中所有平台类型',
maxHeight:300
});
$('#channel').multiselect(
{
enableFiltering: true,
nonSelectedText:'请选择渠道',
filterPlaceholder:'搜索',
nSelectedText:'项被选中',
includeSelectAllOption:true,
selectAllText:'全选/取消全选',
allSelectedText:'已选中所有渠道',
maxHeight:300
});

$("#platform_type").bind("click",function(){

$("#channel option[value]").remove();
});
$("#platform_type").bind("change",function(){

var platform_type_ids=$("#platform_type").val();//获取所有的平台类型

if(platform_type_ids!=null){
var ulr='{:U('/Admin/System/User/getChannel')}';
$.ajax({
type:"GET",
url:ulr,
data:{ids:platform_type_ids},
dataType:"json",
success:function(data){
$("#channel option[value]").remove();

$(data).each(function(k,v){
$('#channel').append(
//selected="selected"
$('<option ></option>').text(v["cn_name"]).val(v["id"])
);
});
$('#channel').multiselect('rebuild');
$("#channel").multiselect( 'refresh' );
}
});
}else{

$('#channel').multiselect('destroy');
$('#channel').empty();
$('#channel').multiselect({
enableCaseInsensitiveFiltering : true,
nonSelectedText:'请选择渠道',
maxHeight:300

});


}

});



</script>
</block>

 

posted @ 2015-07-28 11:23  麦田守望者~  阅读(16681)  评论(0编辑  收藏  举报