[英]Combine two Javascripts together
*編輯了我的帖子。 我需要幫助編輯下面的腳本。 此腳本用於在索引視圖頁面上對表中的元素字段進行顏色格式化。 我需要能夠將另一個字段值為“Schstatus”的元素字段進行顏色格式化,就像另一個字段的值為“出勤”一樣。 我需要添加什么來定義“Schstatus”字段的格式?
{(function() {
"use strict";
// Run an event when the record list page is displayed
kintone.events.on('app.record.index.show', function(event) {
//Retrieve an array of field elements of the fields with field code of "Attendance"
var elStatus = kintone.app.getFieldElements('Attendance');
//Change the properties of the retrieved field elements for each record
for (var i = 0; i < elStatus.length; i++)
{
var record = event.records[i];
if (record['Attendance']['value'] === "Call Out")
{
elStatus[i].style.color = 'white';
elStatus[i].style.backgroundColor = "#e74c3c";
}
else if (record['Attendance']['value'] === "Pending")
{
elStatus[i].style.color = 'black';
elStatus[i].style.backgroundColor = "#ffcc00";
}
else if (record['Attendance']['value'] === "Confirmed")
{
elStatus[i].style.color = 'white';
elStatus[i].style.backgroundColor = "#a3b815";
}
}
});
})();
}
將elStatuss作為函數參數傳遞。
function your_function_name(elStatuss) {
"use strict";
// Run an event when the record list page is displayed
kintone.events.on('app.record.index.show', function(event) {
//Retrieve an array of field elements of the fields with field code of one that is given as param.
var elStatus = kintone.app.getFieldElements(elStatuss);
//Change the properties of the retrieved field elements for each record
for (var i = 0; i < elStatus.length; i++)
{ var record = event.records[i];
if (record['Attendance']['value'] === "No-Show")
{ elStatus[i].style.color = 'white';
elStatus[i].style.backgroundColor = 'red'; }
else if (record['Attendance']['value'] === "Late")
{ elStatus[i].style.color = "#a023bc"; }
else if (record['Attendance']['value'] === "On-Time")
{ elStatus[i].style.color = 'green'; }
}
});
僅在函數var elStatus = kintone.app.getFieldElements(elStatuss);
更改並且此行var elStatus = kintone.app.getFieldElements(elStatuss);
然后使用它your_function_name('Attendance');
或your_function_name('Schstatus');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.