AEM Forms 6.5導入了定義JavaScript函式的功能,這些函式可用於使用規則編輯器定義複雜業務規則。
AEM Forms提供許多此類自訂函式,但您需要定義自己的自訂函式,並在多個表單中使用。
若要定義您的第一個自訂函式,請依照下列步驟操作:
/**
* Get List of County names
* @name getCountyNamesList Get list of county names
* @return {OPTIONS} drop down options
*/
function getCountyNamesList()
{
var countyNames= [];
countyNames[0] = "Santa Clara";
countyNames[1] = "Alameda";
countyNames[2] = "Buxor";
countyNames[3] = "Contra Costa";
countyNames[4] = "Merced";
return countyNames;
}
/**
* Covert UTC to Local Time
* @name convertUTC Convert UTC Time to Local Time
* @param {string} strUTCString in Stringformat
* @return {string}
*/
function convertUTC(strUTCString)
{
var dt = new Date(strUTCString);
console.log(dt.toLocaleString());
return dt.toLocaleString();
}
請 請參閱jsdoc 以取得關於註解javascript函式的詳細資訊。
上述程式碼有兩個功能:
getCountyNamesList — 傳回字串陣列
convertUTC — 將UTC時間戳轉換為本地時區
開啟js.txt並貼上下列程式碼並儲存您的變更。
#base=js
functions.js
#base=js行會指定JavaScript檔案的目錄。
以下幾行表示JavaScript檔案相對於基本位置的位置。
如果您在建立自訂函式時遇到問題,歡迎 下載並安裝此包 在AEM例項中。
以下影片會逐步帶您了解在適用性表單的規則編輯器中使用自訂函式的相關步驟