简体   繁体   中英

Combine two Javascripts together

*Edited my post. I need help editing the script below. This script is used to color format a element field in a table on the index view page. I need to be able to color format another element field which has a field value of "Schstatus" just as the other field has a value of "Attendance". What do I need to add to define the formatting of the "Schstatus" field?

{(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";

             }

        }

    });
})();
}

Pass your elStatuss as function parameter.

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';          }

    }

});

Made changes just in the function decleration and this line var elStatus = kintone.app.getFieldElements(elStatuss);

and then use it your_function_name('Attendance'); or your_function_name('Schstatus');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM