1. 程式人生 > >jeecg自定義按鈕使用exp屬性不起作用

jeecg自定義按鈕使用exp屬性不起作用

config 是你 參考 not alt 當我 ati ica die

為什麽要寫這篇文章?

之前寫過一篇類似的文章 jeecg筆記之自定義顯示按鈕exp屬性,但是有些小夥伴留言參考後不起作用,當時我的 jeecg 版本為3.7.5,最終以版本不同,暫時擱淺了。
今天,重新回到這個問題,一起去討伐這個不起效果的 exp

前臺參考界面

因為重新拉取的新版本 jeecg(3.8),沒有合適的場景演示,那麽就參考一下官方的使用案例吧。

Online表單開發界面(cgFormHeadList.jsp)

技術分享圖片

主要參考代碼部分:

<t:dgFunOpt exp="isDbSynch#eq#N" title="sync.db" funname="doDbsynch(id,content)" urlclass="ace_button"  urlfont="fa-database"/>
<t:dgFunOpt exp="isDbSynch#eq#Y&&jformType#ne#3" funname="addbytab(id,content)" title="form.template" urlclass="ace_button" urlStyle="background-color:#5F9EA0" urlfont="fa-cog"></t:dgFunOpt>
<t:dgFunOpt exp="isDbSynch#eq#Y&&jformType#ne#3" funname="addlisttab(tableName,content)" title="function.test" urlStyle="background-color:#18a689;" urlclass="ace_button" urlfont="fa-gavel"></t:dgFunOpt>
<t:dgFunOpt exp="isDbSynch#eq#Y&&jformType#ne#3" funname="popMenuLink(tableName,content)" title="config.place" urlStyle="background-color:#1a7bb9;" urlclass="ace_button" urlfont="fa-cog" ></t:dgFunOpt>
<t:dgFunOpt funname="copyOnline(id)" title="復制表單" operationCode="copyOnlineTable" urlclass="ace_button" urlfont="fa-copy"></t:dgFunOpt>
<t:dgFunOpt exp="hasPeizhi#ne#0" funname="propertyTable(id)" title="配置表" urlclass="ace_button" urlfont="fa-cog"></t:dgFunOpt>

當我看到新版本這幾行代碼的時候,感覺哪裏怪怪的,這跟上幾個版本差不多呀!

信誓旦旦的去比對了一下兩個文件的差異,如下:

技術分享圖片

事實證明,確實沒有差距,只是新版本寬度樣式稍微變化了一下。

分析一行代碼部分(功能測試按鈕):

<t:dgFunOpt exp="isDbSynch#eq#Y&&jformType#ne#3" funname="addlisttab(tableName,content)" title="function.test" urlStyle="background-color:#18a689;" urlclass="ace_button"  urlfont="fa-gavel"></t:dgFunOpt>

表達式:isDbSynch#eq#Y&&jformType#ne#3

  • isDbSynch:屬性字段,註意是實體字段,非數據庫表字段列名稱
  • eq:條件判斷中的等於,ne 為不等於
  • &&:邏輯且,左右條件同時滿足時才顯示,多條件的使用,|| 邏輯或。

補充

關於 exp 具體實現代碼部分,在此就不展開說明了,感興趣的小夥伴可以看一下這個類 DataGridTag.java 的 2552 行代碼:

String exp = dataGridUrl.getExp();// 判斷顯示表達式
if (StringUtil.isNotEmpty(exp)) {
String[] ShowbyFields = exp.split("&&");
for (String ShowbyField : ShowbyFields) {
int beginIndex = ShowbyField.indexOf("#");
int endIndex = ShowbyField.lastIndexOf("#");
String exptype = ShowbyField.substring(beginIndex + 1, endIndex);// 表達式類型
String field = ShowbyField.substring(0, beginIndex);// 判斷顯示依據字段
String[] values = ShowbyField.substring(endIndex + 1, ShowbyField.length()).split(",");// 傳入字段值
String value = "";
for (int i = 0; i < values.length; i++) {
value += "‘" + "" + values[i] + "" + "‘";
if (i < values.length - 1) {
value += ",";
}
}
if ("eq".equals(exptype)) {
sb.append("if($.inArray(rec." + field + ",[" + value + "])>=0){");
}
if ("ne".equals(exptype)) {
sb.append("if($.inArray(rec." + field + ",[" + value + "])<0){");
}
if ("empty".equals(exptype) && value.equals("‘true‘")) {
sb.append("if(rec." + field + "==‘‘){");
}
if ("empty".equals(exptype) && value.equals("‘false‘")) {
sb.append("if(rec." + field + "!=‘‘){");
}
}
}

最後

雖然上方,我通過 3.8 版本重新嘗試了 exp 屬性,但是你仍然存在無法生效的問題的話,歡迎交流~。

文章作者:niceyoo
文章地址:https://www.cnblogs.com/niceyoo/p/10520278.html
如果覺得文章對你有所幫助,右下方點個推薦~


jeecg自定義按鈕使用exp屬性不起作用