jeecg框架,<t:dictSelect>控件使用,
介绍:
该控件会编译成<select><option value="XX">XX</option></select>
1、采用数据字典方式赋值:
<t:dictSelect field="productionWorkposition" type="select" typeGroupCode="station" hasLabel="false" datatype="*" title="工位" defaultVal="${kyProductionDefinitionPage.productionWorkposition}" extendJson='{onchange="setTechName(value)"}'></t:dictSelect>
- typeGroupCode:数据字典编码
- extendJson:添加属性方法
- defaultVal-->option元素的默认值
2、直接查询数据库表赋值:
<t:dictSelect field="productionSynchId" type="list" dictCondition=" where product_id = '${kyProductionDefinitionPage.productId }'" dictTable="ky_production_synch" dictField="production_bh" dictText="production_name" defaultVal="${kyProductionDefinitionPage.productionSynchId}" hasLabel="false" datatype="*" title="同步工序"></t:dictSelect>
- dictCondition:查询条件
- dictTable:数据库表名
- dictField:value值
- dictText:text值
3、类似二级联动效果
- 两个<t:dictSelect>联动效果
function setTechName(value) {
$("#productionName").val($('select:first option:selected').text());
getSynch();
}
function getSynch(){
//第一个<t:dictSelect>编译成<select>,获取它的value值
let station = $('select:first option:selected').val();
$.ajax({
type:"post",
url:"technologyDefinition.do?getSynch",
dataType:"json",
async:false,
data:{station:station},
success:function(data){
if(data.obj){
var synch = data.obj.synch;
//遍历编译后的<select>中的<option>,将value等于需要显示的值的option设置为selected
$("select[name='productionSynchId']").find("option").each(function () {
var $this = $(this);
console.log("text:"+$this.text()+"value:"+$this.val());
if($.trim($this.text()) == $.trim(synch)) {
$this.attr("selected", true);
}
});
}else{
tip(data.msg);
}
}
});
}
- 一个<t:dictSelect>,一个<select>联动
//html
<td>
<t:dictSelect id="kyProstopList[#index#].reason" field="kyProstopList[#index#].reason" type="select" hasLabel="false" title="停机原因" extendJson="{class:'form-control input-sm', onchange:'stopChange(this)'}" typeGroupCode="stophj" ></t:dictSelect>
</td>
<td>
<select id="kyProstopList[#index#].code" name="kyProstopList[#index#].code" class="form-control input-sm" maxlength="32" datatype="*" ignore="ignore"/>
</td>
//javascript
function stopChange(that) {
let td = $(that).parent().parent().children();
let info = td.eq(4).children("select");
let line = $("#line").val().indexOf('焊');
if(line != -1){
line = "hj";
}else{
alertTip("请选择线别");
return;
}
info.empty();
if($(that).val() === '')
return;
$.ajax({
type:"post",
url:"kySmtdayController.do?getStopInfo",
dataType:"json",
async:false,
data:{bad:$(that).val(),line:line},
success:function(data){
if(data.obj) {
for(let i=0; i < data.obj.length; i++)
info.append("<option value='"+data.obj[i].code+"'>"+data.obj[i].code+"</option>");
}
}
});
}