<div class="layui-inline">
<label class="layui-form-label">場 站:</label>
<div class="layui-input-inline">
<select class="selectpicker" id="slpk" data-live-search="true" style="width:200px;height:500px"
data-selected-text-format="count" data-live-search-placeholder="搜索"
multiple data-max-options="1" name="請選擇地區" th:field="*{objId}" onchange="change(this)"></select>
<input type="hidden" id="hiddenName" th:field="*{name}">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">氣象站:</label>
<div class="layui-input-inline">
<select class="selectpicker" id="qxz" data-live-search="true" style="width:200px;height:500px"
data-selected-text-format="count" data-live-search-placeholder="搜索"
multiple data-max-options="1" name="請選擇地區" th:field="*{sdate}" onchange="change1()"></select>
<input type="hidden" id="hiddenName1" th:field="*{edate}" >
</div>
</div>
$(function() {
$.ajax({
crossDomain: true,
xhrFields: {
withCredentials: true
},
async:false,
type:"post",
url:[[@{/getSelectFarm}]],
data:{type:2},
datatype:"json",
success:function(data){
var select = $("#slpk");
select.append(data.rbaseNetList);
var typeArr=[[${commonBean.objId}]];
if(typeArr != null){
select.selectpicker('val', typeArr);
initQxz1(typeArr);
}
},
error:function(data){
alert("error!")
}
});
});
function change(obj){
var options=$("#slpk option:selected");
$("#hiddenName").val(options.text());
var id = obj.options[obj.selectedIndex].value;
initQxz(id);
}
function change1(){
var options=$("#qxz option:selected");
$("#hiddenName1").val(options.text());
}
function initQxz1(id){
$.ajax({
crossDomain: true,
xhrFields: {
withCredentials: true
},
async:false,
type:"post",
url:"/getGfqxz",
data:{farmid:id},
dataType:"json",
success:function(data){
$("#qxz").html("");
var select = $("#qxz");
select.append(data.qxzs);
}
})
}
function initQxz(id){
$.ajax({
crossDomain: true,
xhrFields: {
withCredentials: true
},
async:false,
type:"post",
url:"/getGfqxz",
data:{farmid:id},
dataType:"json",
success:function(data){
$("#qxz").html("");
var select = $("#qxz");
select.append(data.qxzs);
$("#qxz").selectpicker('refresh');
change1();
}
})
}